Calling DLL fucn with ShortString param fails

From: Muzzy (leyandrew_at_yahoo.com)
Date: 12/31/03

  • Next message: Qzg=FCr=20TU=D0RUL?=: "Re: Make a program unkillalbe"
    Date: Wed, 31 Dec 2003 02:17:01 -0500
    
    

    Hi,

    I have a .DLL library providing me with a function which returns false
    or true depending on some conditions. It's declared in DLL as:

    //----------------------
    extern "C" __declspec(dllexport) _stdcall bool VPNStart();
    //----------------------

    And i call it from an app (using func Start):

    //----------------------
    typedef bool (*HVPNSTART)(void);

    bool Start()
    {
       HINSTANCE hLib = LoadLibrary("MyDLL.DLL");
       if (hLib == NULL) {
         MessageBox(0, "Unable to Load MyDLL.DLL", "Error", MB_OK);
         return false;
       }
       HVPNSTART vs = (HVPNSTART)GetProcAddress(hLib, "VPNStart");
       if (vs == NULL) {
         MessageBox(0, "Failed calling VPNStart", "Error", MB_OK);
         FreeLibrary(hLib);
         return false;
       }
       bool result = vs();

       //MessageBox(0, "VPNStart Loaded!", "SUCCESS", MB_OK);
       if (result) MessageBox(0, "TRUE", "RESULT", MB_OK);
       else MessageBox(0, "FALSE", "RESULT", MB_OK);

       FreeLibrary(hLib);
       return result;
    }
    //----------------------

    Everything works perfect until... i add an argument to the DLL fucn
    VPNStart:
    //----------------------
    extern "C" __declspec(dllexport) _stdcall bool VPNStart();
    //----------------------

    So i change the main app code:
    //----------------------
    typedef bool (*HVPNSTART)(ShortString);
    bool Start( ShortString s ) {...}

    It starts to act WEIRD!!! When i trace (F8 -:)) thru the 'Start()' func
    i see the following - after i load library, i write down it's address,
    say ':013A000'.
    But after the line 'result = vs(s)', the hLib address changes to
    ':8000004', and of course after i 'FreeLibrary' and return, it gives me
    an access violation... How come the address of library handle could change?

    I also tried to pass char* instead of ShortString, doesn't work also...

    Any ideas, PLEASE!!!

    Thank you,
    Andrey


  • Next message: Qzg=FCr=20TU=D0RUL?=: "Re: Make a program unkillalbe"

    Relevant Pages

    • Re: MFC DLL - ExitInstance hang on WaitForSingleObject
      ... Here is a simple pooling class implemented into a MFC DLL project. ... BOOL CPooler::StartPooling ... // Look for empty place in the array and create the Pooler ... void Enqueue(POOLER_CALLBACK_FN f, LPVOID p); ...
      (microsoft.public.vc.mfc)
    • Re: Problem using WndProc MessageWindow with native DLL
      ... what you are doing is calling a DLL function from ... > private System.Windows.Forms.Button Identify; ... > protected override void Dispose(bool disposing) ... > private void InitializeComponent() ...
      (microsoft.public.dotnet.framework.compactframework)
    • Re: DLL and communication from another process exe
      ... It is risky to do cross-thread SendMessage, but if all you want is a bool, then if you are ... If I were doing this in a DLL, I might consider creating a UI thread in the DLL that ... creates an invisible window that handles the communication. ... EXE gets SendMessage from DLL ...
      (microsoft.public.vc.mfc)
    • Re: Problems using a c++ dll in VB.net Compact Framework
      ... A C++ bool is not a System.Byte. ... > The eVC++ dll struct is defined as ... >>> CFLauncher.exe: 0x80000002: Datatype Misalignment, after a few uses of>>> the dll, but I am struggling to pinpoint where. ... >>>>> To test this new functionality, we have written a VB.net>>>>> application. ...
      (microsoft.public.dotnet.framework.compactframework)
    • Re: Weird Behaviour...argh
      ... Could there be difficulties because the DLL is a Win32 project, ... > Martin Stich wrote: ... >> bool HasSettings() { ...
      (microsoft.public.vc.language)