Delphi dll - powerbuilder calling funtions from dll

I'm developing a dll file in Delphi 7 in order to use it in a Powerbuilder 
10.5 application. I get strange results in PB when i try to pass a string 
through a function or procedure. I've tried pchar, pwidechar, lpstr, lpctstr 
in D7 and string or REF string in PB, but nothing seems to be working 
properly. The function in D7 is quite simple, i just take a string for 
input, encode it and return an encoded string for output. In PB i get a lot 
of "squares" in my output string. There seems to be a problem reading (from 
PB) the memory address that is pointed out from Delphi's dll. Is there 
anything i need to try in PB that is more compatible with D7 pchars or 
strings?

0
NickDim
11/19/2007 12:47:01 PM
📁 sybase.ole-ocx-activex
📃 6324 articles.
⭐ 0 followers.

💬 7 Replies
👁️‍🗨️ 1784 Views


PB expects a DLL to have the functions exported in __STDCALL format.
On 19 Nov 2007 04:47:01 -0800, "NickDim" <nickdim@globo.gr> wrote:
>I'm developing a dll file in Delphi 7 in order to use it in a Powerbuilder 
>10.5 application. I get strange results in PB when i try to pass a string 
>through a function or procedure. I've tried pchar, pwidechar, lpstr, lpctstr 
>in D7 and string or REF string in PB, but nothing seems to be working 
>properly. The function in D7 is quite simple, i just take a string for 
>input, encode it and return an encoded string for output. In PB i get a lot 
>of "squares" in my output string. There seems to be a problem reading (from 
>PB) the memory address that is pointed out from Delphi's dll. Is there 
>anything i need to try in PB that is more compatible with D7 pchars or 
>strings?
>
0
Bruce
11/19/2007 3:03:29 PM
 Thank you for your quick response.
I've already tried the STDCALL format (as well as other formats too), but I 
get the same results in PB.

"Bruce Armstrong [TeamSybase]" <NOCANSPAM_bruce.armstrong@teamsybase.com> 
wrote in message news:od93k3ln97p3a5fafdr0oc17126m6b1i4h@4ax.com...
>
> PB expects a DLL to have the functions exported in __STDCALL format.
>
> On 19 Nov 2007 04:47:01 -0800, "NickDim" <nickdim@globo.gr> wrote:
>
>>I'm developing a dll file in Delphi 7 in order to use it in a Powerbuilder
>>10.5 application. I get strange results in PB when i try to pass a string
>>through a function or procedure. I've tried pchar, pwidechar, lpstr, 
>>lpctstr
>>in D7 and string or REF string in PB, but nothing seems to be working
>>properly. The function in D7 is quite simple, i just take a string for
>>input, encode it and return an encoded string for output. In PB i get a 
>>lot
>>of "squares" in my output string. There seems to be a problem reading 
>>(from
>>PB) the memory address that is pointed out from Delphi's dll. Is there
>>anything i need to try in PB that is more compatible with D7 pchars or
>>strings?
>>
> 

0
NickDim
11/20/2007 9:08:30 AM
STDCALL is the format to go with. Passing strings as ref string or 
string should just work without problems. Did you take into account that 
PB 10.5 is unicode?
When writing C DLL stuff I debug the PB IDE and application from the C 
IDE to see what's actually being passed.
Regards
Arthur
NickDim wrote:
>  Thank you for your quick response.
> I've already tried the STDCALL format (as well as other formats too), but I 
> get the same results in PB.
> 
> 
> 
> "Bruce Armstrong [TeamSybase]" <NOCANSPAM_bruce.armstrong@teamsybase.com> 
> wrote in message news:od93k3ln97p3a5fafdr0oc17126m6b1i4h@4ax.com...
>> PB expects a DLL to have the functions exported in __STDCALL format.
>>
>> On 19 Nov 2007 04:47:01 -0800, "NickDim" <nickdim@globo.gr> wrote:
>>
>>> I'm developing a dll file in Delphi 7 in order to use it in a Powerbuilder
>>> 10.5 application. I get strange results in PB when i try to pass a string
>>> through a function or procedure. I've tried pchar, pwidechar, lpstr, 
>>> lpctstr
>>> in D7 and string or REF string in PB, but nothing seems to be working
>>> properly. The function in D7 is quite simple, i just take a string for
>>> input, encode it and return an encoded string for output. In PB i get a 
>>> lot
>>> of "squares" in my output string. There seems to be a problem reading 
>>> (from
>>> PB) the memory address that is pointed out from Delphi's dll. Is there
>>> anything i need to try in PB that is more compatible with D7 pchars or
>>> strings?
>>>
> 
> 
0
Arthur
11/20/2007 10:29:52 AM
Thanks for that tip Arthur.
Finally, this issue was solved:
I used a function with two pwidechar variables and pwidechar for return 
value in Delphi's 7 dll.
Then i take the two values from PB i pass them into two delphi strings. Then 
i use them to do the encoding. The encode function takes two strings (the 
text to encode and the key) and returns an encoded string.
Finally i pass the encoded string from Delphi's "UTF8Decode" function and 
return it as pwidechar to the function's result.
After overcoming this problem, another one occurred. When I test the program 
in design time (from PB), everything works fine and the program returns the 
correct values, but when I test it in runtime, the program crashes (I 
believe while accessing the dll):

AppName: test.exe                  AppVer: 1.0.0.1      ModName: msvcr71.dll
ModVer: 7.10.3052.4               Offset: 00010440
I don't know if there is anything I can do from the Delphi's dll point of 
view or is there something I'm missing in my PB exe?
Thanks in advance for any help.


"Arthur Hefti" <arthur@catsoft.ch> wrote in message 
news:4742b720@forums-1-dub...
> STDCALL is the format to go with. Passing strings as ref string or string 
> should just work without problems. Did you take into account that PB 10.5 
> is unicode?
> When writing C DLL stuff I debug the PB IDE and application from the C IDE 
> to see what's actually being passed.
>
> Regards
> Arthur
>
> NickDim wrote:
>>  Thank you for your quick response.
>> I've already tried the STDCALL format (as well as other formats too), but 
>> I get the same results in PB.
>>
>>
>>
>> "Bruce Armstrong [TeamSybase]" <NOCANSPAM_bruce.armstrong@teamsybase.com> 
>> wrote in message news:od93k3ln97p3a5fafdr0oc17126m6b1i4h@4ax.com...
>>> PB expects a DLL to have the functions exported in __STDCALL format.
>>>
>>> On 19 Nov 2007 04:47:01 -0800, "NickDim" <nickdim@globo.gr> wrote:
>>>
>>>> I'm developing a dll file in Delphi 7 in order to use it in a 
>>>> Powerbuilder
>>>> 10.5 application. I get strange results in PB when i try to pass a 
>>>> string
>>>> through a function or procedure. I've tried pchar, pwidechar, lpstr, 
>>>> lpctstr
>>>> in D7 and string or REF string in PB, but nothing seems to be working
>>>> properly. The function in D7 is quite simple, i just take a string for
>>>> input, encode it and return an encoded string for output. In PB i get a 
>>>> lot
>>>> of "squares" in my output string. There seems to be a problem reading 
>>>> (from
>>>> PB) the memory address that is pointed out from Delphi's dll. Is there
>>>> anything i need to try in PB that is more compatible with D7 pchars or
>>>> strings?
>>>>
>> 
0
NickDim
11/26/2007 12:55:34 PM
when i run the program lunch the visual studio just-in-time debugger
with the message
"An unhandled win32 exception occurred in dongle.exe (6128 )"
and after this the folling message
"Unhandled exception at 0x7c350440 in dongle.exe: 0xC0000005: Access 
violation reading location 0x0019282c."
what do i have to do
Thanks in advance

"NickDim" <nickdim@globo.gr> wrote in message news:474ac246@forums-1-dub...
> Thanks for that tip Arthur.
>
> Finally, this issue was solved:
>
> I used a function with two pwidechar variables and pwidechar for return 
> value in Delphi's 7 dll.
>
> Then i take the two values from PB i pass them into two delphi strings. 
> Then i use them to do the encoding. The encode function takes two strings 
> (the text to encode and the key) and returns an encoded string.
>
> Finally i pass the encoded string from Delphi's "UTF8Decode" function and 
> return it as pwidechar to the function's result.
>
> After overcoming this problem, another one occurred. When I test the 
> program in design time (from PB), everything works fine and the program 
> returns the correct values, but when I test it in runtime, the program 
> crashes (I believe while accessing the dll):
>
>
> AppName: test.exe                  AppVer: 1.0.0.1      ModName: 
> msvcr71.dll
>
> ModVer: 7.10.3052.4               Offset: 00010440
>
> I don't know if there is anything I can do from the Delphi's dll point of 
> view or is there something I'm missing in my PB exe?
>
> Thanks in advance for any help.
>
>
>
>
>
> "Arthur Hefti" <arthur@catsoft.ch> wrote in message 
> news:4742b720@forums-1-dub...
>> STDCALL is the format to go with. Passing strings as ref string or string 
>> should just work without problems. Did you take into account that PB 10.5 
>> is unicode?
>> When writing C DLL stuff I debug the PB IDE and application from the C 
>> IDE to see what's actually being passed.
>>
>> Regards
>> Arthur
>>
>> NickDim wrote:
>>>  Thank you for your quick response.
>>> I've already tried the STDCALL format (as well as other formats too), 
>>> but I get the same results in PB.
>>>
>>>
>>>
>>> "Bruce Armstrong [TeamSybase]" 
>>> <NOCANSPAM_bruce.armstrong@teamsybase.com> wrote in message 
>>> news:od93k3ln97p3a5fafdr0oc17126m6b1i4h@4ax.com...
>>>> PB expects a DLL to have the functions exported in __STDCALL format.
>>>>
>>>> On 19 Nov 2007 04:47:01 -0800, "NickDim" <nickdim@globo.gr> wrote:
>>>>
>>>>> I'm developing a dll file in Delphi 7 in order to use it in a 
>>>>> Powerbuilder
>>>>> 10.5 application. I get strange results in PB when i try to pass a 
>>>>> string
>>>>> through a function or procedure. I've tried pchar, pwidechar, lpstr, 
>>>>> lpctstr
>>>>> in D7 and string or REF string in PB, but nothing seems to be working
>>>>> properly. The function in D7 is quite simple, i just take a string for
>>>>> input, encode it and return an encoded string for output. In PB i get 
>>>>> a lot
>>>>> of "squares" in my output string. There seems to be a problem reading 
>>>>> (from
>>>>> PB) the memory address that is pointed out from Delphi's dll. Is there
>>>>> anything i need to try in PB that is more compatible with D7 pchars or
>>>>> strings?
>>>>>
>>>
> 

0
NickDim
11/28/2007 5:16:26 PM
Seems to me a problem in proper memory allocation, meaning that you 
access memory in your DLL that's not in the passed data. E.g writing to 
the 11th byte of a 10 byte blob. An other problem might be that you 
don't acquire / release memory in the DLL properly.
This often works in design mode or debugging and blows the application 
during runtime.
Arthur
NickDim wrote:
> when i run the program lunch the visual studio just-in-time debugger
> with the message
> "An unhandled win32 exception occurred in dongle.exe (6128 )"
> and after this the folling message
> "Unhandled exception at 0x7c350440 in dongle.exe: 0xC0000005: Access 
> violation reading location 0x0019282c."
> what do i have to do
> 
> Thanks in advance
> 
> 
> "NickDim" <nickdim@globo.gr> wrote in message news:474ac246@forums-1-dub...
>> Thanks for that tip Arthur.
>>
>> Finally, this issue was solved:
>>
>> I used a function with two pwidechar variables and pwidechar for return 
>> value in Delphi's 7 dll.
>>
>> Then i take the two values from PB i pass them into two delphi strings. 
>> Then i use them to do the encoding. The encode function takes two strings 
>> (the text to encode and the key) and returns an encoded string.
>>
>> Finally i pass the encoded string from Delphi's "UTF8Decode" function and 
>> return it as pwidechar to the function's result.
>>
>> After overcoming this problem, another one occurred. When I test the 
>> program in design time (from PB), everything works fine and the program 
>> returns the correct values, but when I test it in runtime, the program 
>> crashes (I believe while accessing the dll):
>>
>>
>> AppName: test.exe                  AppVer: 1.0.0.1      ModName: 
>> msvcr71.dll
>>
>> ModVer: 7.10.3052.4               Offset: 00010440
>>
>> I don't know if there is anything I can do from the Delphi's dll point of 
>> view or is there something I'm missing in my PB exe?
>>
>> Thanks in advance for any help.
>>
>>
>>
>>
>>
>> "Arthur Hefti" <arthur@catsoft.ch> wrote in message 
>> news:4742b720@forums-1-dub...
>>> STDCALL is the format to go with. Passing strings as ref string or string 
>>> should just work without problems. Did you take into account that PB 10.5 
>>> is unicode?
>>> When writing C DLL stuff I debug the PB IDE and application from the C 
>>> IDE to see what's actually being passed.
>>>
>>> Regards
>>> Arthur
>>>
>>> NickDim wrote:
>>>>  Thank you for your quick response.
>>>> I've already tried the STDCALL format (as well as other formats too), 
>>>> but I get the same results in PB.
>>>>
>>>>
>>>>
>>>> "Bruce Armstrong [TeamSybase]" 
>>>> <NOCANSPAM_bruce.armstrong@teamsybase.com> wrote in message 
>>>> news:od93k3ln97p3a5fafdr0oc17126m6b1i4h@4ax.com...
>>>>> PB expects a DLL to have the functions exported in __STDCALL format.
>>>>>
>>>>> On 19 Nov 2007 04:47:01 -0800, "NickDim" <nickdim@globo.gr> wrote:
>>>>>
>>>>>> I'm developing a dll file in Delphi 7 in order to use it in a 
>>>>>> Powerbuilder
>>>>>> 10.5 application. I get strange results in PB when i try to pass a 
>>>>>> string
>>>>>> through a function or procedure. I've tried pchar, pwidechar, lpstr, 
>>>>>> lpctstr
>>>>>> in D7 and string or REF string in PB, but nothing seems to be working
>>>>>> properly. The function in D7 is quite simple, i just take a string for
>>>>>> input, encode it and return an encoded string for output. In PB i get 
>>>>>> a lot
>>>>>> of "squares" in my output string. There seems to be a problem reading 
>>>>>> (from
>>>>>> PB) the memory address that is pointed out from Delphi's dll. Is there
>>>>>> anything i need to try in PB that is more compatible with D7 pchars or
>>>>>> strings?
>>>>>>
> 
> 
0
Arthur
11/29/2007 5:16:17 AM
This probably has something to do with the rather unique way Delphi handles 
strings:
http://delphi.about.com/od/objectpascalide/l/aa103003a.htm
http://delphi.wikia.com/wiki/Creating_DLLs
"Arthur Hefti" <arthur@catsoft.ch> wrote in message 
news:474e4b21$1@forums-1-dub...
> Seems to me a problem in proper memory allocation, meaning that you access 
> memory in your DLL that's not in the passed data. E.g writing to the 11th 
> byte of a 10 byte blob. An other problem might be that you don't acquire / 
> release memory in the DLL properly.
> This often works in design mode or debugging and blows the application 
> during runtime.
>
> Arthur
>
> NickDim wrote:
>> when i run the program lunch the visual studio just-in-time debugger
>> with the message
>> "An unhandled win32 exception occurred in dongle.exe (6128 )"
>> and after this the folling message
>> "Unhandled exception at 0x7c350440 in dongle.exe: 0xC0000005: Access 
>> violation reading location 0x0019282c."
>> what do i have to do
>>
>> Thanks in advance
>>
>>
>> "NickDim" <nickdim@globo.gr> wrote in message 
>> news:474ac246@forums-1-dub...
>>> Thanks for that tip Arthur.
>>>
>>> Finally, this issue was solved:
>>>
>>> I used a function with two pwidechar variables and pwidechar for return 
>>> value in Delphi's 7 dll.
>>>
>>> Then i take the two values from PB i pass them into two delphi strings. 
>>> Then i use them to do the encoding. The encode function takes two 
>>> strings (the text to encode and the key) and returns an encoded string.
>>>
>>> Finally i pass the encoded string from Delphi's "UTF8Decode" function 
>>> and return it as pwidechar to the function's result.
>>>
>>> After overcoming this problem, another one occurred. When I test the 
>>> program in design time (from PB), everything works fine and the program 
>>> returns the correct values, but when I test it in runtime, the program 
>>> crashes (I believe while accessing the dll):
>>>
>>>
>>> AppName: test.exe                  AppVer: 1.0.0.1      ModName: 
>>> msvcr71.dll
>>>
>>> ModVer: 7.10.3052.4               Offset: 00010440
>>>
>>> I don't know if there is anything I can do from the Delphi's dll point 
>>> of view or is there something I'm missing in my PB exe?
>>>
>>> Thanks in advance for any help.
>>>
>>>
>>>
>>>
>>>
>>> "Arthur Hefti" <arthur@catsoft.ch> wrote in message 
>>> news:4742b720@forums-1-dub...
>>>> STDCALL is the format to go with. Passing strings as ref string or 
>>>> string should just work without problems. Did you take into account 
>>>> that PB 10.5 is unicode?
>>>> When writing C DLL stuff I debug the PB IDE and application from the C 
>>>> IDE to see what's actually being passed.
>>>>
>>>> Regards
>>>> Arthur
>>>>
>>>> NickDim wrote:
>>>>>  Thank you for your quick response.
>>>>> I've already tried the STDCALL format (as well as other formats too), 
>>>>> but I get the same results in PB.
>>>>>
>>>>>
>>>>>
>>>>> "Bruce Armstrong [TeamSybase]" 
>>>>> <NOCANSPAM_bruce.armstrong@teamsybase.com> wrote in message 
>>>>> news:od93k3ln97p3a5fafdr0oc17126m6b1i4h@4ax.com...
>>>>>> PB expects a DLL to have the functions exported in __STDCALL format.
>>>>>>
>>>>>> On 19 Nov 2007 04:47:01 -0800, "NickDim" <nickdim@globo.gr> wrote:
>>>>>>
>>>>>>> I'm developing a dll file in Delphi 7 in order to use it in a 
>>>>>>> Powerbuilder
>>>>>>> 10.5 application. I get strange results in PB when i try to pass a 
>>>>>>> string
>>>>>>> through a function or procedure. I've tried pchar, pwidechar, lpstr, 
>>>>>>> lpctstr
>>>>>>> in D7 and string or REF string in PB, but nothing seems to be 
>>>>>>> working
>>>>>>> properly. The function in D7 is quite simple, i just take a string 
>>>>>>> for
>>>>>>> input, encode it and return an encoded string for output. In PB i 
>>>>>>> get a lot
>>>>>>> of "squares" in my output string. There seems to be a problem 
>>>>>>> reading (from
>>>>>>> PB) the memory address that is pointed out from Delphi's dll. Is 
>>>>>>> there
>>>>>>> anything i need to try in PB that is more compatible with D7 pchars 
>>>>>>> or
>>>>>>> strings?
>>>>>>>
>> 
0
Bruce
11/29/2007 5:50:51 PM
Reply: