Hi, I am having some problems integrating a DLL inside my Delphi 2007 application.
I suspect I'm doing something wrong with call parameters. At the moment, I have 2 questions, but I think they are related to eachother.
1) First call using a DLL: from a .h file:
extern "C" { __declspec(dllexport) HRESULT Startup(char* version); }
This call should initialize the DLL and provide me with the version of the DLL. HRESULT must be 0, and the version pointer must contain the version.
My Delphi Code:
function Startup(var version: Pchar): HRESULT; cdecl; stdcall; external 'myDLL.dll';
And the actual call:
var res : HRESULT; Name1 : PChar; test : AnsiString; buf2: array [0..20] of AnsiChar; begin FillChar(buf2,20,0); Name1:= @buf2[0]; res := RdmStartup(Name1);
But as a result of 0, the call was successful.
Then my second problem: I need to call a function in a DLL that will open a COM port.
.h:
extern "C" { __declspec(dllexport) HRESULT Open(HWND hWnd, int Port, DWORD BaudRate, DWORD Interval); }
And my Delphi announce:
function Open(hWnd: HWND;Port : integer;BaudRate:LongInt;Interval:LongInt): HRESULT; cdecl; stdcall; external 'myDLL.dll';
and I call it:
res:= Open(self.Handle,5,115200,500);
And here I get a rejection of the DLL in the res variable. I also have the source of the DLL, and the failure I get is related to the part where the DLL checks if the parameters are valid, if they are valid, it will continue, otherwise return the error I am getting now.
What he checks:
if(hWnd == NULL) { return false; } if(BaudRate != 2400 && BaudRate != 9600 && BaudRate != 38400 && BaudRate != 115200) { return false; } if(IntervalTimer < 300) { return false; } std::string strPortName = lexical_cast<std::string>( format("COM%d") % Port); std::string strPortName(lpPortName.c_str()); std::string::size_type loci = strPortName.find("COM"); if( loci == std::string::npos ) { return false; } return true;
And one of these above returns false on my call, because if the result of this function is false, the DLL gives the error that I am now getting in the results. Does anyone have an idea of ββwhat I'm doing wrong?
I tried many combinations for types, in the end, I stuck to the conversion found at: http://www.drbob42.com/delphi/headconv.htm I also tried different ways to read the char pointer, but they all failed .. ...
So, at this point, I know that I am successfully communicating with the DLL, since I get different HRESULT for two calls, but I suspect that my parameters are not working as it should.
I am using Delphi 2007, and the C ++ DLL is with VS2010.