It is currently Wed Nov 25, 2020 11:59 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Problem with wrapping a library
PostPosted: Thu Sep 10, 2020 8:06 pm 
Offline
User
User

Joined: Thu Aug 30, 2018 7:41 am
Posts: 20
Yo! I am back to PB after some time of absence. I am wrapping a Windows DLL that is written in C ++ to be used with PB. I will show you the fragment of the documentation and then my attempt to wrap it. The DLL compiles, even the log is created if I call the DLL from another application, but the other functions are not executed.
Here is the fragment of the library's documentation
int Initial(wchar_t* appkey, wchar_t* seckey, ZDCloudAPICallBack zdcCallBack)
typedef void(WINAPI *ZDCloudAPICallBack)(int type);
[out] int type
int SpeakAsync(wchar_t* text, BOOL bWindowChangedStop)
And now my prototype definitions:
int SpeakAsync(wchar_t* text, BOOL bWindowChangedStop)
Below I am showing the procedure that is called on attaching my DLL to the current process:

Code:
ProcedureDLL AttachProcess(Instance)
  OpenLibrary(0, "ZDCloudAPI.dll")
  Initial = GetFunction(0, "Initial")
  UnInitial = GetFunction(0, "UnInitial")
  SpeakAsync = GetFunction(0, "SpeakAsync")
  StopSpeak = GetFunction(0, "StopSpeak")
  CreateFile(1, "log.txt")
  result = Initial("apikey","secretkey",#Null)
  WriteInteger(1, result)
EndProcedure

It seems like the "Initial" function is not even called properly.
I am sorry for this chaotic post, but I really look desperately for the solution. I have tried using a "p-unicode" parameter instead of wchar_t, but that didn't work either.
The use of normal strings is the result of my todays battle with the problem.

// Edit: Code-Tags added (Kiffi)


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with wrapping a library
PostPosted: Fri Sep 11, 2020 8:47 am 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5056
Location: Germany
Code:

PrototypeC ZDCloudAPICallBack(type.i)

PrototypeC.i Proto_Initial(appkey.p-Unicode, seckey.p-Unicode, zdcCallBack.ZDCloudAPICallBack)
PrototypeC Proto_UnInitial()
PrototypeC.i Proto_SpeakAsync(text.p-Unicode, bWindowChangedStop.i)
PrototypeC Proto_StopSpeak()

Global ZDCloudAPI.i

Global Initial.Proto_Initial
Global UnInitial.Proto_UnInitial
Global SpeakAsync.Proto_SpeakAsync
Global StopSpeak.Proto_StopSpeak


Procedure Logging(Text$)
  Protected File.i
 
  File = OpenFile(#PB_Any, "log.txt", #PB_File_Append)
  If File
    WriteStringN(File, FormatDate("%yyyy%mm%dd %hh%ii%ss ", Date()) + Text$)
    CloseFile(File)
  EndIf
EndProcedure


Procedure AttachProcess()
  ZDCloudAPI = OpenLibrary(#PB_Any, "ZDCloudAPI.dll")
  If ZDCloudAPI
    Initial = GetFunction(ZDCloudAPI, "Initial")
    UnInitial = GetFunction(ZDCloudAPI, "UnInitial")
    SpeakAsync = GetFunction(ZDCloudAPI, "SpeakAsync")
    StopSpeak = GetFunction(ZDCloudAPI, "StopSpeak")
   
    result = Initial("apikey", "secretkey", #Null)
    Logging(Str(result))
  Else
    Logging("Was not able to load ZDCloudAPI.dll")
  EndIf
EndProcedure


Maybe you have to remove the C from the Prototypes. This depends on the dll.

Test it first as a normal programm before you try to put it in a dll.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with wrapping a library
PostPosted: Fri Sep 11, 2020 8:48 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 740
I dont see why it should work (unless PB does more than tranfering the call).

MSDN:
Code:
There are significant limits on what you can safely do in a DLL entry point. See General Best Practices for specific Windows APIs that are unsafe to call in DllMain. If you need anything but the simplest initialization then do that in an initialization function for the DLL. You can require applications to call the initialization function after DllMain has run and before they call any other functions in the DLL.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with wrapping a library
PostPosted: Fri Sep 11, 2020 2:08 pm 
Offline
User
User

Joined: Thu Aug 30, 2018 7:41 am
Posts: 20
Wow! Now my client application (written in C #) throws an access violation exception. I really don't wanna use C ++ for this!


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with wrapping a library
PostPosted: Fri Sep 11, 2020 5:50 pm 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5056
Location: Germany
Sorry, but your answer tells me nothing.

Have you tested it as normal program not as dll?
Have you removed the C from the Prototype command?


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with wrapping a library
PostPosted: Fri Sep 11, 2020 6:13 pm 
Offline
User
User

Joined: Thu Aug 30, 2018 7:41 am
Posts: 20
Hi,
I actually haven't used PrototypeC as I know the DLL uses STDCALL convention. I havent tried using it as a normal program yet. I will do it soon.
infratec wrote:
Sorry, but your answer tells me nothing.

Have you tested it as normal program not as dll?
Have you removed the C from the Prototype command?


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with wrapping a library
PostPosted: Sat Sep 19, 2020 6:13 pm 
Offline
User
User

Joined: Thu Aug 30, 2018 7:41 am
Posts: 20
Hi,
I am really sorry to ask this question, but I guess I will need more help.
Can someone contact me via E-Mail (nuno69a at gmail dot com) and try to help me diagnose my problem? The reason I am requesting a mail help is that this DLL requires some API information which I cannot publish


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with wrapping a library
PostPosted: Sat Sep 19, 2020 8:21 pm 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5056
Location: Germany
I sent you a PM.
For somethink like this I prefer PMs.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with wrapping a library
PostPosted: Mon Sep 21, 2020 5:53 pm 
Offline
User
User

Joined: Thu Aug 30, 2018 7:41 am
Posts: 20
Yo! I have replied. The DLL in question (ZZDCloudAPI) is written in C ++.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with wrapping a library
PostPosted: Mon Sep 21, 2020 8:35 pm 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5056
Location: Germany
For a C++ DLL you may need interfaces:

viewtopic.php?p=440419#p440419
viewtopic.php?p=412798#p412798


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with wrapping a library
PostPosted: Wed Sep 23, 2020 8:43 pm 
Offline
User
User

Joined: Thu Aug 30, 2018 7:41 am
Posts: 20
WHy would I need interfaces? This library is not OOP. It uses standard Win32 types and strucytures. The only exception is the callback.
infratec wrote:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye