Results 1 to 5 of 5

Thread: linking DLL's..

  1. #1

    linking DLL's..

    Hi all,

    i have a basic plugin system using DLL's with certain procedures in them, ie:

    function cxHeader: TcxPluginHeader; stdcall;
    ..
    procedure cxInitialize; stdcall;
    ..
    procedure cxRender; stdcall;
    ..
    procedure cxFinalize; stdcall;
    ..

    and these are exported, then i created a class structor to use to call these plugins:

    class
    cxHeader: function: TcxPluginHeader;
    cxInitialize: procedure;
    cxRender: procedure;
    cxFinalize: procedure;
    hPlugin: Integer;

    and in the constructor i have the following code:
    // cxg is a dll
    hPlugin := LoadLibrary('plugin.cxg');
    if hPlugin = 0 Then
    begin
    FreeLibrary(hPlugin);
    Exit;
    end;
    @cxHeader := GetProcAddress(hPlugin, 'cxHeader');
    @cxInitialize := GetProcAddress(hPlugin, 'cxInitialize');
    @cxRender := GetProcAddress(hPlugin, 'cxRender');
    @cxFinalize := GetProcAddress(hPlugin, 'cxFinalize');

    try
    Header := cxHeader;
    excpet
    showmessage('failed');
    end;

    this all seems to work and it is all created, but once everything has been created i get a
    Debugger fault notification
    saying:
    Project H:\cxgViewer.exe faulted with message: 'access violation at 0x004638fd: Read of address 0x00000028' Process stopped. Use step or run to continue.

    i don't seem to be getting any information back from the dll, is their some thing that i am doing wrong?

    i have tried looking around on the internet and they mention the same method that im using or using the external command.
    This is really confusing me :?

    thanks for any help
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #2

    linking DLL's..

    You have to declare your function pointers with stdcall before using them - this is important, since stdcall isn't the default calling convention. i.e.,

    cxHeader: function: TcxPluginHeader; stdcall;
    cxInitialize: procedure; stdcall;
    cxRender: procedure; stdcall;
    cxFinalize: procedure; stdcall;

    Make sure that you've exported the functions from the DLL too! It's could be a good move to specify a name in the exports clause for each exported proc/func, just in case...

    Do you not want to call FreeLibrary only if the DLL loads okay later on, once you're done with the function pointers? I tested the FreeLibrary on a non-existant library and it returned 0, indicating an error. I can't say that I've looked at DLLs much, though, so that might be wrong, but still...

    As an aside: Sly has written a pretty cool OpenGL terrain generator. You might want to have a look because it uses a DLL-based plug-in system (I think it's over here).
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  3. #3

    linking DLL's..

    hi,

    thanks for your reply.

    i have tried it with and without stdcall in both the DLL and the Application, and it does the same.

    in the DLL they are being exported like:
    Code:
    Exports
      cxHeader name 'cxHeader',
      cxInitialize name 'cxInitialize',
      cxRender name 'cxRender',
      cxFinalize name 'cxFinalize';
    i have tried it with and without 'Name' but still the same thing happens. its like it is'nt being loaded up correctly, i am getting a Handle value but thats is about it.

    i used 'FreeLibrary' when the handle value is 0 and when the plugin manager is destroyed.

    great thanks, i will have a look
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  4. #4

    linking DLL's..

    Here's a quick DLL test project for you, basically nabbed from the help files: dlltest.zip (12K). Maybe the solution's in there.
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  5. #5

    linking DLL's..

    Thanks

    I have looked through them both and i changed some parts and now works perfectly (well almost :roll: )

    i had:
    Code:
    TManager = class
    private
      cxHeader&#58; function&#58; TcxPluginHeader; stdcall;
      ....
    and changed it to:
    Code:
    TcxHeader = function&#58;  TcxPluginHeader; stdcall;
    ....
    TManager = class
    private
       cxHeader&#58; TcxHeader;
       ....
    im not sure why but now it works :?

    any way thanks for your help!
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •