Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 8 Jahren, 4 Monaten
Letzter Beitrag:
vor 8 Jahren, 4 Monaten
Beteiligte Autoren:
David Egan, King, Fabrice Harari, Piet van Zanten, Ruben Sanchez Peña, king

String value from DLL

Startbeitrag von David Egan am 09.04.2010 08:58

I'm converting an old app from clarion to Windev which uses a DLL which I still want to use. In clarion I declare a variable as CString and can then call the DLL as Variable = DLLFunctionName(Parameter1 , Parameter2 etc). I can then directly use the variable with the returned string variable. How do I get a string value from Windev? Windev only allows an integer value as a return value and despite trying various things that's all I seem to get. Looking at the help file doesn't help me & I'm still just as confused.




See StringRetrieve in the Help.


von Ruben Sanchez Peña - am 09.04.2010 09:11
I've done that but it hasn't helped. The code I have is
li_add is int = CallDLL32("Exp2.dll","GetSerial",ls_Detail,0,0,0,0,0,0)
ls_serial = StringRetrieve(li_add,srASCIIZAddress)
This should return a 24 character string but all I get is a single character, which bears no resemblance to any of the characters which should be returned. I have tried passing ls_detail as a string and as an ASCIIIZ string but with exactly the same result.



von David Egan - am 09.04.2010 19:47
Hi David,

Are you running a 64 bits Windows version?
You could try to declare the integer result as "system int".
The integer will be 4 bits or 8 bits automatically depending on the system.

If everything else fails you can also try the transfer function.
In windev the result of a dll call is allways the address of the result.
You declare the resulting variable first (string, strucure or anything) and then you transfer the result into it. The variable you declare should have the exact same structure as the dll's result.
See the help for transfer.


von Piet van Zanten - am 10.04.2010 08:52
Have a look of my of piece of work as shown below in 2002 to see if any help for u.

//OK 2002.06.27
hInst is long int
nErrMsg is long int = 1552 //for windev 7, declare int instead of long int
sBuffer is fixed string on 250
hInst = LoadDLL("c:\oracle\msgdll.dll")
If hInst = 0 then
Error("Error during loading")
info(CallDLL32("msgdll","OraMsg",nErrMsg,&sBuffer, 250))


von king - am 10.04.2010 14:37
Thanks Guys
Still no good I'm afraid. I've used CallDLL32 plenty of times before without a problem but in every case the return string has been included in the parameters. This one is different in that the result is not in a parameter but in 2 other languages (Clarion & Powerflex) the DLL has simply returned the string. I'm using 32 bit WinXP and I would have thought that Windev would return the address of the return string which I could then access with StringRetrieve. I don't know if I'm missing something pretty basic here but the problem with using Transfer Piet is that I don't know the source string to transfer. Your solution King is essentially what I use when the result is included as a parameter.
The declaration in C++ is
typedef char *( __stdcall *pGetSerial ) ( char*, int, int, int, int, int, int );
and in VB
Private Declare Function GetSerial Lib "Exp2" (ByVal SerialPassword As String, ByVal RegOptions As Integer, ByVal SerialExpireDays As Integer, _
ByVal RegExpire As Integer, ByVal RegExpireDay As Integer, ByVal RegExpireMonth As Integer, ByVal RegExpireYear As Integer) As String

Any other suggestions would be much appreciated


von David Egan - am 11.04.2010 00:53
Hi David

do you have any idea of the maximum length of the string? If yes, try to declare a variable as asciiZ longer than the maximum possible and use transfer to copy your result in it on the length of your variable-1. The ending zero should do the rest

Best regards

von Fabrice Harari - am 11.04.2010 02:32

Mind if u mail me yr DLL as I wrote my own DLLs and have no trouble at all even in C++..
I'd like to give it a try n I'm using WD/B/M 14 and it's under 32-bit XPs.


von King - am 11.04.2010 16:36

Re: String value from DLL - SOLVED

Thanks guys, problem solved & I feel rather stupid! :-( Couldn't see the wood for the trees. I should know better but I believed the help file which states that CallDll32 automatically loads the DLL so I didn't use LoadDll first. Because this is just a little app for internal use I took what I thought was the easy option. Use LoadDll & StringRetrieve works exactly as expected.
Now that it's working I can vaguely recall striking this some years ago. Getting (more) forgetful as I'm getting older!


von David Egan - am 11.04.2010 19:51
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.