English 中文(简体)
调用 Delphi 代码中的视觉 C++DLL 函数
原标题:Calling Visual C++ DLL s functions from Delphi code

In a Delphi program I m using a DLL to control an external executable. The DLL is written in Visual C++. In C++ the code to use DLL is:

// defining pointer s type to a function compatible with  launcher  function:
typedef int (WINAPI* PFI_HD_ST_N)(HDC, LPCSTR, int);
…
…
HINSTANCE m_hiDLLCTRL;  // handle to DLL instance
PFI_HD_ST_N pfStart;    // pointer to function that starts external program

// initialization
m_hiDLLCTRL = NULL;
pfStart = NULL;

// links DLL dynamically
m_hiDLLCTRL = LoadLibrary(“ExtProgCTRL.dll”);

// if DLL has been loaded
If (m_hiDLLCTRL)
    // I get the address to funcion that launches ExtProg
    pfStart = ( PFI_HD_ST_N) GetProcAddress( m_hiDLLCTRL, “ExtProgStart” );
// launches external program
If ( pfStart )
    // hWnd is handle to window where I want do draw 
    pfStart -> ( GetDC ( hWnd ), “C:\Programs\ExtProg”, 1 ); 

我在戴尔菲有一样的代码

private
    DLLHandle: THandle;
    XInt: function: Integer: cdecl;

...
implementation
...
...
DLLHandle := LoadLibrary( ExtProgCTRL.dll );
if DLLHandle <> 0 then
begin
    @XInt := GetProcAddress(DLLHandle,   ExtProgStart);
    if @XInt <> nil then
    begin
        MessageDlg( Function ExtProgStart loaded ! , mtError, mbOKCancel, 0);
        ...
        ...
    end;
end;

它似乎工作正确, 但我无法找到 Delphi 代码的最后指令, 启动外部程序...

pfStart -> ( GetDC ( hWnd ), “C:\Programs\ExtProg”, 1 );

戴尔菲什么情况?

我已经改变了:

private
    DLLHandle: THandle;
    XInt: function(DC: HDC; Text: PAnsiChar; SomeInt: Integer); Integer: cdecl;

...
implementation
...
retval: Integer;

DLLHandle := LoadLibrary( ExtProgCTRL.dll );
if DLLHandle <> 0 then
begin
    @XInt := GetProcAddress(DLLHandle,   ExtProgStart);
    if @XInt <> nil then
    begin
        MessageDlg( Function ExtProgStart loaded ! , mtError, mbOKCancel, 0);
       retval := XInt(GetDC(hWnd),  C:ProgramsExtProg , 1);
    end;
end;

but now I have on last instruction : retval := XInt... the following error: DCC Error : ( expected but ) found (parenthesis after hWnd)

最佳回答

您需要声明 >>Xint 像这样 :

XInt: function(DC: HDC; Text: PAnsiChar; SomeInt: Integer): Integer; stdcall;
  1. You need to declare a parameter list that matches the definition in the C++ code.
  2. I don t know meaningful names for the parameters but I m sure you can supply them.
  3. The C++ code specifies the WINAPI calling convention which matches stdcall in Delphi.

然后你可以这样称呼它:

retval := XInt(GetDC(hWnd),  C:ProgramsExtProg , 1);
问题回答

暂无回答




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签