Re: passing a string to a dll

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



"SteveR" <srussell@xxxxxxxxxxxxxxxxxxxxxx> wrote in message news:OIsWUtm%23HHA.5160@xxxxxxxxxxxxxxxxxxxxxxx
These comments about LPCTSTR in the DLL, how much do they apply to a shared DLL? Not that mine is necessarily going to be shared, but that's the type I chose by default when I created it. Is this also about overhead? Should I avoid C++ as much as possible inside the DLL?

If the parameter is a CString (or pointer or reference to CString) then any exe that wants to use the DLL must use MFC. A lot of things can go wrong passing "smart" objects into a DLL. It can work but the build settings for exe and DLL have to be just right.

But LPCTSTR is not a "smart" object. It is not even C++. It is a simply a pointer to char or wchar_t. This kind of parameter makes the DLL usable from C.

Using LPCTSTR is not really about overhead, it is about K.I.S.S. It avoids all the potential issues with passing objects


If I move these strings into the DLL function, I will be happy to get them out of the exe; but what impact does this have on performance, memory consumption or anything else? Am I gaining or losing anything?

The only performance loss caused by a DLL is the extra program startup time needed to load the DLL. Once it has been loaded into memory there is no significant difference between calling a function in the exe and calling a function in the DLL.


And if I move the alphanumeric code array to the DLL as I intend, how do I build the array with LPCTSTR instead of CString?

In the exe, no change. You can pass a CString to an LPCTSTR parameter.
In the DLL, you would assign the LPCTSTR to a CString.

.



Relevant Pages

  • Re: VC++ 6.0 DLL Using CString used in VC++ 2008
    ... CString in both return codes and function arguments. ... There is no way I can change the DLL, so my only idea is that I need to ... compiler-independent interface. ... fantasy world, compiler-dependent interfaces never change). ...
    (microsoft.public.vc.mfc)
  • Re: Parameter of dlls function
    ... The type of my local variable is CString but both exe and dll use the same ... MFC version. ...
    (microsoft.public.vc.mfc)
  • Re: DLL erstellen
    ... Funktion einen CString übergeben und in der DLL per AfxMessageBox ausgegeben. ... Selbst wenn ich das Hauptfenster der EXE als CDialog* an die DLL übergebe, kann ich in der DLL ein MoveWindow drauf machen ohne das was crasht. ... So etwas schmiert ja schon in einer einzelnen EXE ab, wenn Du mehrere Threads verwendest und CWnd* weitergibst. ... "Use MFC in a Static Library" ...
    (microsoft.public.de.vc)
  • Re: VC++ 6.0 DLL Using CString used in VC++ 2008
    ... CString in both return codes and function arguments. ... There is no way I can change the DLL, so my only idea is that I need to ... compiler-independent interface. ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... Should I avoid C++ as much as possible inside the DLL? ... If you want to build an MFC extension DLL, I think that passing CString ... exported CString built in ANSI into an exe built in Unicode, ... or other string classes *inside* the DLL implementation. ...
    (microsoft.public.vc.mfc)