It is currently Fri May 24, 2013 8:01 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 10:10 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Aug 05, 2003 11:30 pm
Posts: 405
Hi all,

hope you can help me with a problem.
I have a dll where functions need some parameter a value as unsigned char.
Sample:
Code:
Dll_Function(struct zint_symbol *symbol, unsigned char *input, int length)


How i must call the dll function to send a unsigned char as parameter?

Thanks
Nico

_________________
my live space


Top
 Profile  
 
 Post subject: Re: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 10:20 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 1441
Location: Germany
Hi,

for your example you need no unsignged char, since it is a pointer.
So you need a *Ptr as parameter or an integer.

Bernd


Top
 Profile  
 
 Post subject: Re: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 10:20 am 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 13, 2007 12:42 pm
Posts: 1307
Location: Manchester, UK
unsigned char is 0 to 255, so use variable type of Ascii = .a


Top
 Profile  
 
 Post subject: Re: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 10:22 am 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 13, 2007 12:42 pm
Posts: 1307
Location: Manchester, UK
or as infratec pointed out, a POINTER of the variable, which is type Ascii.


Top
 Profile  
 
 Post subject: Re: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 10:23 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
nicolaus wrote:
I have a dll where functions need some parameter a value as unsigned char.
Sample:
Code:
Dll_Function(struct zint_symbol *symbol, unsigned char *input, int length)


How i must call the dll function to send a unsigned char as parameter?

With prototypes you should use p-ascii if the parameter is only [out], means you give
the buffer to the chars, but you don't receive something from it (p-ascii does not
translate back the return buffer after the function call).
Code:
Prototype proto_Dll_Function(*symbol.zint_symbol, input.p-ascii, length.l)


Without using prototype with p-ascii:

In ASCII mode you can just give the address to a string: @"my string"

In Unicode mode you have to convert the string to ASCII first and give the address to that buffer.

If you get something returned in the buffer, you give the address of a (string)buffer. buffer.s = Space(length) -> give @buffer to the function.
In Unicode mode you do buffer.s = PeekS(@buffer,-1,#PB_Ascii) to get the ASCII string after the function returned.


Last edited by Danilo on Thu May 10, 2012 11:04 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 10:24 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 1441
Location: Germany
With prototypes:
Code:
Prototype Proto_Dll_Function(*symbol, *input, length.i)

Prototype Proto_Dll_Function(*symbol.zint_symbol_str, *input.a, length.i)
Bernd


Top
 Profile  
 
 Post subject: Re: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 10:58 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 28, 2003 12:01 am
Posts: 349
Danilo wrote:
In ASCII mode you can just give the address to a string: @"my string"

In Unicode mode you have to convert the string to ASCII first and give the address to that buffer.


see ==> pseudotypes in purebasic help:
PureBasic Help :: Pseudotypes wrote:
p-ascii:

acts as a string type, but will always convert the string to ascii before
calling the function, even when the program is compiled in unicode mode.
It is very useful when accessing a shared library which doesn't have unicode
support in an unicode program for example.

_________________
Windows 8 / Windows 7 / Windows XP (als VM)
PB Last Final / Last Beta Testing


Top
 Profile  
 
 Post subject: Re: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 11:03 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
helpy wrote:
Danilo wrote:
In ASCII mode you can just give the address to a string: @"my string"

In Unicode mode you have to convert the string to ASCII first and give the address to that buffer.


see ==> pseudotypes in purebasic help:
PureBasic Help :: Pseudotypes wrote:
p-ascii:

acts as a string type, but will always convert the string to ascii before
calling the function, even when the program is compiled in unicode mode.
It is very useful when accessing a shared library which doesn't have unicode
support in an unicode program for example.

Of course. The separated lines were other ways, without using prototypes and p-ascii.
Sorry, i did not make this clear enough.


Top
 Profile  
 
 Post subject: Re: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 11:11 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 28, 2003 12:01 am
Posts: 349
Danilo wrote:
Of course. The separated lines were other ways, without using prototypes and p-ascii.
Sorry, i did not make this clear enough.

Thank you Danilo,

for your kind answer!

I read it too fast! If I read your text more carefully, I would have understand it!
Both lines refer to the previous line: "Without using prototype with p-ascii:"

I misunderstood it!

guido

_________________
Windows 8 / Windows 7 / Windows XP (als VM)
PB Last Final / Last Beta Testing


Top
 Profile  
 
 Post subject: Re: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 9:31 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 6465
infratec wrote:
Prototype Proto_Dll_Function(*symbol.zint_symbol_str, *input.a, length.i)

Here *input.a should be *input.Ascii or merely *input as qualifying pointers as native types does nothing and leads to confusion. The compiler should disallow it imho but it lets it go.

_________________
Veni, vidi, vici.


Top
 Profile  
 
 Post subject: Re: DLL Parameter and unsigned char problem
PostPosted: Thu May 10, 2012 9:42 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4715
Location: Berlin - Germany
netmaestro wrote:
The compiler should disallow it imho but it lets it go.

+ 1 :)

_________________
PureBasic 5.11 | Windows 7 SP1 (x64) | Mageia 3 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye