Results 1 to 7 of 7

Thread: Simple DLL...

  1. #1

    Thread Starter
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540

    Simple DLL...

    I'm writing an application in Delphi which is going to be expandable by using DLL's for plugins. The Delphi part is not a problem obviously, but I want to make sure that it is compatible with C++ DLL's too.

    I don't know much about C++, so I need one of you guys to do me a favour: write a very simple DLL which takes two parameters and shows them in a MessageBox.

    The first parameter will be an 'HWND' type (which should cause no problems), but the second is a PChar (that's what it's called in Delphi, it's a pointer to the first character of a string, should be C++ compatible, *char or something like that?).

    I only have Borland C++ Builder installed here, so I can compile it if it's compatible...


    Thanks...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Sorry, I lost my sample dlls. I just can't remember how to do them.
    Last edited by CornedBee; Nov 17th, 2001 at 04:33 AM.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540

    Unhappy ...

    I will go trough some tutorials if I can't get an answer here, but I don't want to learn C++ just for this, so if anyone has a sample though I would appreciate it a lot...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The function would look like this:
    Code:
    #include <windows.h>
    
    void __stdcall ShowMB(HWND hwnd, char* str)
    {
        char buffer[200]; // or more if it produces failures
        wsprintf(buffer, "Window: %d, String: %s", (int)hwnd, str);
        MessageBox(NULL, buffer, "The DLL", MB_OK);
    }
    and you need a .def file that has this lines:
    EXPORTS
    ShowMB


    But I forgot the exact def file syntax.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Thanks, that really helped me. Couldn't find the .def file thing, but the C++ Builder help had the solution:


    Code:
    #include <windows.h>
    #pragma argsused
    
    extern "C" __declspec(dllexport) void __stdcall test(HWND hWnd, char* pPath);
    
    void __stdcall test(HWND hWnd, char* pPath)
    {
      char buffer[200];
      wsprintf(buffer, "Window: %d\n\nPath: %s", (int)hWnd, pPath);
      MessageBox(NULL, buffer, "DLL Test", MB_OK || MB_ICONINFORMATION);
    }

    That works fine, although the messagebox shows OK - CANCEL instead of just ok, MB_OK should be standard API, but anyways, it works so I can safely continue coding
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    MB_OK || MB_ICONINFORMATION
    || is the logical OR operator - it returns either true or false.

    Use | instead, for a bitwise OR (which combines the bit values of the two operands).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yeah, and since MB_ICONEXCLAMATION is something > 0, it is evaluated as true which later becomes 1, which is MB_OKCANCEL.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width