#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    2
    Rep Power
    0

    passing an LPSTR to a dll function call


    i'm passing an LPSTR to a c++ dll function call from a c++ exe application. but i'm getting an exception thrown when i try to do this. here is my code:

    LPSTR sInstalledProducts;
    int* dummy;

    typedef int (__stdcall FUNCPROC)(HWND, LPSTR, int*);

    HINSTANCE hInstance;
    FUNCPROC* pFunction;

    VERIFY(hInstance = ::LoadLibrary(sSysDir));
    VERIFY(pFunction = (FUNCPROC*)::GetProcAddress(hInstance, "Find_Installed_Products"));

    int i = (*pFunction)(this->GetSafeHwnd(), sInstalledProducts, dummy);


    What am I doing wrong? My problem has something to do with sInstalledProducts.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    Just checking the obvious stuff here:
    1. Is sInstalledProducts pointing to an actual string or not. You can't just do:

    LPSTR foo;
    function(foo);

    because foo is a pointer to an array of char, not an array of char itself. You're going to have to point foo to an actual char array, otherwise you're only passing an uninitialized pointer to the function.
    LPSTR foo;
    TCHAR bar[100];
    foo = bar;
    function(foo); // Either use this
    function(bar); // or this.

    2. Also, I think you're passing your third argument incorrectly as well. Since your prototype is (HWND, LPSTR, int *), shouldn't your call also be:
    int i = (*pFunction)(this->GetSafeHwnd(), sInstalledProducts, &dummy);
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    2
    Rep Power
    0
    thanks that worked!

IMN logo majestic logo threadwatch logo seochat tools logo