Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This should be easy - what am I missing?

Status
Not open for further replies.

DjangMan

Programmer
Jun 1, 2001
1,786
CA
I'm having a problem getting a DLL to work. I'm writing the app and the dll in D6. I'm using FastMM4 as the first unit in both the App and the DLL's project uses clause.

The problem is that the DLL is getting garbage for the aFilename parameter. Then the function iLoadandParseFile returns an integer indicating that the file was not found.

I figure that there's something simple that I've overlooked. Help!

DLL function:
Code:
uses
  FastMM4,
  SysUtils,
  Classes,
  ImportUnit_Sample in 'ImportUnit_Sample.pas' {dm_DB: TDataModule};

function LoadAndParseFile(aFilename: PChar): integer; StdCall;
var
 TheFile: string;
begin
  if assigned(dm_DB)=False then
    dm_DB := Tdm_DB.Create(nil);

  TheFile := StrPas(aFilename);

  //I have a separate function that does the
  //actual work.
  result := dm_DB.iLoadandParseFile(TheFile);
end;

App function call:
Code:
function LoadAndParseFile(aFilename: string): integer; external 'DatasetDLL.dll';

procedure LoadTheList;
var
  x: integer;
  s:string;
begin

    s:='c:\django.txt';
    x := LoadandParseFile(PChar(s));

end;
 
You're declaring LoadAndParseFile with a String parameter one one side, and a PChar on the other. I'd say this is your problem.

You should be able to make both a ShortString variable - Windows files are limited to 255 characters anyway, although with FastMM4 you may be able to use standard String variables, not sure.
 
string variables are allowed with fastmm4

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top