Passing a string from a D3 exe to a BCB dll
Posted on 1997-12-26
I am trying to pass a string as an argument from a D3 exe to a BCB dll. The BCB docs indicate that if one uses a char pointer, it is not required to use bcbmm.dll. A doc at the Borland website, "Extending Delphi with DLLs" provides snippets illustrating how this is done. Unfortunately I can not get this to work.
extern "C" __pascal __declspec(dllexport) int AddVals(int nA, int nB, int nC, int nD)
This is from "Extending Delphi with DLLs" found at the Borland website
int far _export pascal PassCharPtr(char far* strA)
MessageBox(NULL, strA, "GPC_TPL", MB_OK);
function ADDVALS(nA,nB,nC,nD: integer):integer; stdcall; far external 'GPC_TPL.DLL' index 2;
function PASSCHARPTR(strParam: PChar):integer; external 'GPC_TPL' index 1;
procedure TForm1.Button1Click(Sender: TObject);
StringLength = 255;
strA: array[0..StringLength] of char;
nRetVal := ADDVALS(1,2,3,4);
StrPCopy(strA, 'Hello World!');
nRetVal := PASSCHARPTR(strA);
The PassCharPtr method in the dll does not receive the string as a argument and returns the length of the string as 3 no matter what the string length really is.
BCB suggests adding bcbmm.lib to both the dll and exe. I cannot seem to add bcbmm.lib to the D3 exe.
When I add ShareMem.pas to the dll project and put ShareMem at the head of my uses list, I get the same results plus when I close the exe an InvalidPointer exception is thrown.
Suggestions on how to successfully pass a string (<255 char) as an argument from a D3 exe to a BCB dll method will be greatly appreciated.