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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLL with strings not working!

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
Hello all -

I have recently created a DLL for my project. I created the dll file, a unit name WordFunctions with 3 functions and one procedure. The procedure requires a string so I have included ShareMem in my dll file and the application file. If I comment out the procedure, everything seems to work ok (I can't really test that well because the commented procedure is the main process!). When the string procedure is included and I try to run the program I get the following message:

Cannot debug project unless a host application is defined. Use the Run|Parameters...dialog box.

But I have no clue what I'm suppose to put in the dialog box!

Any suggestions?
Thanks! Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
You need to specify a calling application for you dll. I mean enter your program's name in "Host application" field. Host application is an application that performs function/procedure calls to you DLL.
Hope that helps.

--- markus
 
So even though I have a project group (with my Jury.Dll included and my JMS application) it still doesn't know what to use? Do the debug tools still work when it's run with the Run|Parameters?

Thanks! Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
One more thing, do I need to put my procedure in the exports declaration of the dll file? It really doesn't export (since there's no return). Thanks
Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Ok so I've figured a few things out, but I'm still having problems. As long as my application is highlighted in the program manager (and not the dll), the Run works fine (no parameters). But my procedure is still not working correctly. Maybe if I explain what I've done and what I need to accomplish it would make it easier for you to help!

I have an application called JMS and a dll named Jury. One of the Units in the Jury.dll is called WordFunctions. I have included this unit in the dll uses. I have included all the functions & procedures in the JMS application DLLInterface unit. This unit has these processes:

procedure: LabelPrint
functions: TableFormat, PaperCheck, InchesToPoint

I initially included all these in the exports of the Jury.dll, however the procedure LabelPrint calls all the others and my application only calls LabelPrint, so nothing is really exported (but I'm not clear on what exports does exactly so I could still need the functions there).

So, I'm pretty sure that I have everything where it needs to be and I know the procedure and functions work properly. (Once I got a better idea of how Delphi worked, I started redesigning my 1st attempt by including the DLL and the functions all worked in the previous attempt!) However when I try to run the application I get an error:

Undeclared Identifier 'LabelPrint'

Any idea why it doesn't see the procedure in the DLL? I have included ShareMem in the Uses of the Jury.DLL and the JMS application (again however, I'm not sure that's working either!).

Thanks for any help!

Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
So, I finally got this to work, but I guess I'm still confused. I ended up having to put a uses DLLInterface in each of the forms that call the function/procedures. I was under the impression that you just put in the application source file (not the individual forms within the application). Is this correct?

Thanks,

Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Hey Leslie. I'll start with export clause in DLLs. After this keyword you put only procedures and funcions that are to be called externaly. Procedures and functions that are used only inside of you DLL shouldn't be placed in the export section. Also you can specify an index and a name of an exported procedure/function f.ex.:
Code:
export
 MyCoolProcedure index 1 name 'MyCoolProcedure';
You can specify either an index or a name of the procedure/function or both. Access by index is faster (as far as i remember) but it's not essential with CPUs we have now.
Now about calling procedures and functions from DLL. There are static and dynamic linking of DLLs (AFAIR). Static linking is when in the interface part of your host application you declare a function from the DLL, it can look like this:
Code:
procedure MyCoolProcedure(AParam : Integer); external 'MyLib.dll' name 'MyCoolProcedure';
And then you just call to this procedure/function in your code. Dynamic linking is a little bit more complicated but saves system resource because a DLL is loaded into memory only when you call to a procedure/function from it. If you want to use dynamic linking you should read about LoadLibrary, GetProcAddress, FreeLibrary functions. Here's an example of dynamic linking:
Code:
var 
  AProc : procedure (AParam : Integer);
  hLib  : Cardinal;
begin
  hLib := LoadLibrary('MyLib.dll');
  if (hLib <> INVALID_HANDLE_VALUE)then
  begin
    try
      @AProc := GetProcAddress(hLib, 'MyCoolProcedure');
      if Assigned(AProc)then
       AProc(100); 
    finally
      FreeLibrary(hLib);
    end;
  end;
end;
Hope that all will make sense to you.

--- markus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top