Click to See Complete Forum and Search --> : passing a string to a c++ dll


GetFree
September 5th, 2001, 03:49 PM
hi i need to pass a string for output in a dll function defined like this
GenerateLicenceID(CString sBaseID, int duration, CString *sLicenceID);

and in the VB it is defined like this
Public Declare Function GenerateLicenceID Lib "C:\Final\bin\vproc.dll" Alias "?GenerateLicenceID@@YAXVCString@@HPAV1@@Z" (ByVal sBaseID As String, ByVal duration As Integer, ByRef sLicenceID As String)
but i get memory error and the program terminates

berta
September 5th, 2001, 07:36 PM
when U R using an API DLL the option byval/byref has another meaning.. so to pass a string U maust use byval... also for your concepts is byref...
so tru this code..


'GenerateLicenceID(const char* sBaseID, int duration, Char *sLicenceID);
'it is not define return type.. so defaul is int and not void... but it is necessary the __stdcall option to export as API...

public Declare Function GenerateLicenceID Lib "C:\Final\bin\vproc.dll" Alias "?GenerateLicenceID@@YAXVCString@@HPAV1@@Z" (byval sBaseID as string, byval duration as Integer, byval sLicenceID as string) as integer

public sub prova
dim sbaseid as string
dim duration as integer
dim slicenceid as string*255

'...code...

slicenceid=string(255,0)

debug.print GenerateLicenceID(sbaseid,duration,slicenceid)

debug.print slicenceid
end sub





<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>