Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Denias75

problems with dll and delphi

This topic is 6120 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I have a problem and a few questions concerning Delphi and DLL''s. Okay, the problem first: I built a DLL in VC++ and it compiled fine. Now I want to use this DLL in Delphi. The LoadLibrary function works, but the GetProcAddress functions returns nil (NULL). The DLL function I want to call is: void CreateARF(char *dirStart) Now take a look at the Delphi code: type TCreateARF = procedure(X : PChar); var hLib : THandle; CreateARF : TCreateARF; P : PChar; begin hLib := LoadLibrary(''ARFchiver.dll''); if hLib = 0 then begin MessageBox(frmARFCreator.GetParentHandle(), ''library call failed'', ''ARFCreator'', MB_OK); Application.Terminate(); end else begin @CreateARF := GetProcAddress(hLib, ''CreateARF''); if @CreateARF = nil then begin FreeLibrary(hLib); MessageBox(frmARFCreator.GetParentHandle(), ''function call failed'', ''ARFCreator'', MB_OK); Application.Terminate; end; P := PChar(stvSource.Path); CreateARF(P); end; end; Okay, so far so bad. Now the questions: 1. Since the C++ function expects a char*, I used a PChar in the delphi function because - as far as I know - PChar already is a pointer to char, isn''t it? 2. Why won''t the bloody thing work? It enters the DLL, but when I call the GetProcAddress function, I get a NULL returned instead of the adress or handle to the function! Any help is appreciated!! Alex

Share this post


Link to post
Share on other sites
Advertisement
Well, actually I found the solution to THIS problem. It had something to do with the "C" declaration which wasn''t included in my first version.
Anyway, I have come up with a new problem:

The function in the DLL ''CreateARF(char *dirStart);'' needs - as you can see - a parameter of type char *.
Well, in Delphi there is this data-type called PChar which - as written in the help-file of Delphi - is of type char *.
It didn''t work the way I''ve written it. Though both types seem to be the same - just in different programming languages -, but when I check the parameter dirStart on the Delphi-side before the function is called, it returns the proper value (something like ''C:\''), but in the DLL it returns something weird (like &@.§).

Can anybody help me?

Thanks again!!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!