Click to See Complete Forum and Search --> : String As Byte?
michael2
September 4th, 2001, 03:33 PM
Hi,
I need to link vb code to a C dll, but I have a problem to convert one of the argument of a function.
The function is declare like this in .pas:
test(Filename as Byte)
and like this in .h:
test(char *Filename);
Now I want to pass something like c:\test.txt in parameter, but I always get a run-time error '13' Type Mismatch.
How can I convert a string in byte to pass ByRef to the dll?
Thanks,
Michael
berta
September 4th, 2001, 06:06 PM
U must declare arguments as string but use the option BYVAL.
public declare Test lib "mylib.dll" (byval string filename)
private sub command1_click
dim Filename as string
Filename="myfile.txt"
test(Filename)
end sub
private sub command2_click
test("myfile.txt")
end sub
<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>
michael2
September 5th, 2001, 09:41 AM
I can't change the declaration in .bas
I found how to pass the string in bytes, but I got a new problem... Here is what I do:
public declare Test lib "mylib.dll" (filename as Byte
private sub command1_click
dim Filename() as Byte
Filename="myfile.txt"
test(Filename(0))
end sub
My problem is that Filename does not contain myfile.txt, but contains m0y0f0i0l0e0.0t0x0t0. I have a string terminator after each byte, so the Test function only receive m, because the string is null terminated after it.
How can I have myfile.txt in Filename?
Thanks,
Michael
berta
September 5th, 2001, 09:47 AM
but why not so?
public declare Test lib "mylib.dll" (byval filename as string)
private sub command1_click
dim Filename() as string
Filename="myfile.txt"
test(Filename)
end sub
<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>
berta
September 5th, 2001, 09:57 AM
using option byval...
dim filename as string* 255
filname="myfile.txt"
test(filename)
<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>
DSJ
September 5th, 2001, 10:11 AM
Give this a shot....
public declare Test lib "mylib.dll" (filename as Byte)
private Sub command1_click()
Dim Filename() as Byte
Filename = StrConv("myfile.txt", vbFromUnicode)
Test (Filename(0))
End Sub
michael2
September 5th, 2001, 10:27 AM
That's what I did and it works.
Thanks.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.