Re: problem using delphi dll in vc++

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



thank you all.....I found out there are something wrong about the
function.
So I just want to realize it by myself.Thank you all.


On 4月19日, 上午5时20分, Tamas Demjen <tdem...@xxxxxxxxxx> wrote:
Ryanivanka wrote:
------------------------in c++ .h-------------------------
extern "C" {
__declspec(dllimport) HMODULE __stdcall func1();
}
------------------------------------------------------------

-----------------------in delphi-----------------------------
function func1: dword; stdcall;
----------------------------------------------------------------

They look compatible.

I just don't understand how you were able to link a Delphi DLL
statically. Borland/CodeGear uses OMF-type LIB files, VC++ uses the COFF
format. They're not compatible. Not even for simple import libraries.

So you either have a bug in the Delphi function, or in the import
library. I recommend that you forget about that LIB, and just load the
DLL dynamically:

HINSTANCE dll = LoadLibrary("c:\\path\\to\\my.dll");
typedef HMODULE (__stdcall * PtrFunc1)();
PtrFunc1 func1 =
reinterpret_cast<PtrFunc1>(GetProcAddress(dll, "func1"));



...
// use func1 as if it was a regular C function
...
FreeLibrary(dll);

Of course you have to use GetProcAddress for all the other functions
that the DLL might export as well. It may be a little bit of an extra
work (lots of typing), but you can be 100% sure that the functions are
imported correctly.

I just don't know where your LIB file is coming from, it can't be coming
from Delphi. LIB and OBJ files are generally not portable enough.

Tom

.



Relevant Pages

  • Re: C++ Library needed in Delphi App
    ... Well I figured I might have to write some wrapper functions, but for my current project I must be able to read NeXus format. ... a Delphi application isn't it possible to make that library into a dll ... NCL is designed to be used as a static .lib file that is compiled directly into a C++ executable. ...
    (borland.public.delphi.non-technical)
  • Re: VS.NET 2003 Project References
    ... Tells the linker not to try to link any .lib output generated from this ... .dll files that do not produce a .lib file when built. ... automatically will link the .lib file produced by that child project. ...
    (microsoft.public.vsnet.general)
  • Re: how to use a function from a 3rd party library
    ... >>>The lib file is used only at link time. ... >>>possible for your exe to call the DLL functions at run time. ... >>>the same directory as your debug exe. ...
    (microsoft.public.vc.mfc)
  • Re: Getting linking Error while accessing dll
    ... I have given my .lib filename in the Objects/modules under the Link Tab ... Now when i am trying to use those DLL functions from one of my souce ... You need to tell the linker where it can find that lib file. ... either in the project setup or in the global setup under Tools ...
    (microsoft.public.vc.language)
  • Re: unable to link .lib file to an eVc++4.0 project
    ... the source code and the .lib file are in VC++, ... the definations are in the .lib file which is not getting linked. ... the compilation of a DLL. ... Do just that, compile and run it. ...
    (microsoft.public.windowsce.embedded.vc)