Re: calling methods from DLL

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jeff Partch [MVP] (jeffp_at_mvps.org)
Date: 11/11/04


Date: Thu, 11 Nov 2004 05:42:00 -0600


"LhK-Soft" <someone@somewhere.net> wrote in message
news:419348e7$0$19156$ba620e4c@news.skynet.be...
> "Jeff Partch [MVP]" <jeffp@mvps.org> wrote in message
> news:uroa5i9xEHA.748@TK2MSFTNGP14.phx.gbl...
> > "LhK-Soft" <LhKSoft@discussions.microsoft.com> wrote in message
> > news:8EF55278-A885-4C67-B2BF-70F499446813@microsoft.com...
> > > HINSTANCE myDLL = LoadLibrary("MyLib.DLL");
> > > MyFunc myFunction = (MyFunc)GetProcAddress(myDLL, _T("MyFunc"));
> >
> > While LoadLibrary takes an LPCTSTR, GetProcAddress takes an LPCSTR. The
> > above looks backward. :)
>
> "backward" : what is your point?

The point is that you are always passing "MyLib.DLL" -- an LPCSTR, to
LoadLibrary -- a function that takes an LPCTSTR; and passing _T("MyFunc") --
an LPCTSTR, to GetProcAddress -- a function that only ever takes an LPCSTR.
In other words: backward. You should be doing...

LoadLibrary(_T("MyLib.DLL"))
GetProcAddress(myDLL, "MyFunc")

-- 
Jeff Partch [VC++ MVP]


Relevant Pages

  • Re: calling methods from DLL
    ... > int MyImportedFunc(WPARAM w, LPARAM l) ... While LoadLibrary takes an LPCTSTR, GetProcAddress takes an LPCSTR. ...
    (microsoft.public.vc.mfc)
  • Re: calling methods from DLL
    ... > While LoadLibrary takes an LPCTSTR, GetProcAddress takes an LPCSTR. ... > above looks backward. ...
    (microsoft.public.vc.mfc)
  • Re: LPCSTR, Unicode etc... dont understand
    ... Use LPCTSTR instead of LPCSTR. ... LPCTSTR is a macro that means LPCSTR if UNICODE is undefined ... and LPCWSTR otherwise. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Cant instantiate abstract class
    ... STDMETHOD(THIS_ LPCSTR Name, ... LPD3DXFRAME ... Name parameter is of type LPCSTR in the interface, but LPCTSTR in your ...
    (microsoft.public.vc.language)
  • Re: LPCTSTR and CString
    ... i have a extension dll with this functuon ... LPCTSTR lpcstr; ... IOW, it returns a dangling pointer, which is a fatal flaw. ... extern "C" LPCTSTR WINAPI TestString; ...
    (microsoft.public.vc.mfc)