Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 DLL calling...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

VBBR
Moderator

Brazil
617 Posts

Posted - Jul 10 2004 :  08:35:16 AM  Show Profile  Reply with Quote
If I'm calling an external function from a DLL, where one of its arguments in C is defined as "const char *variable", how should I pass the string? ByVal or ByRef? Should I append a Chr(0) at the end of the string?

Whatever. Who knows...

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jul 10 2004 :  11:15:46 AM  Show Profile  Reply with Quote
I'm not sure if you can pass a constant, seems like that wouldn't work... Also, I don't *think* you can pass an actual "pointer" from VB, but you can pass a reference. They are similar, and I don't know what's different. If you can't tell, my C++ skills are severly lacking, sorry I couldn't be of more help.

Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jul 11 2004 :  01:36:49 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
Is it a double byte character function or a single byte?

For a single byte function, you would declare it as

(ByVal Data As Long)

and then to call the funtion..

Dim S as String: S = "hello"
Call MyFunction(StrPtr(StrConv(S, vbFromUnicode)))


For a double byte string, you would decalre the function the same way.

(ByVal Data As Long)

but when calling the function it would look like

Dim S as String: S = "hello"
Call MyFunction(StrPtr(S))
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jul 11 2004 :  01:49:01 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
You can also decalre the function as ByRef Data As Any instead of ByVal Data As Long.

To call the function when decalared as ByRef Data As Any, you use the following syntax for Single and Double byte systems.

For single byte characters
Dim S as string: s = "hello"
Dim bytArray() as Byte
bytArray = StrConv(S & Chr$(0), vbFromUnicode)
Call MyFunction ( bytArray(0) )

For Double byte characters.
Dim S as string: s = "hello"
Dim bytArray() as Byte
bytArray = S & Chr$(0)
Call MyFunction ( bytArray(0) )
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.09 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.