CString Convert to LPCTSTR
i write DLL file,it is static dll
i want CString type Convert to LPCTSTR
but error
Code:
<<<<<<<<<<<Dll File>>>>>>>>>
<<<<<<<A.H>>>>>>>
class AFX_NOVTABLE dll
{
public:
__declspec(dllexport) LPCTSTR Fun();
};
<<<<<<<A.Cpp>>>>>>
LPCTSTR dll::Fun()
{
CString Rxg=_T("rxg");
LPCTSTR lpszStr=Rxg.GetBuffer();
return lpszStr;
}
<<<<<<<<Exe>>>>>>>>>
#pragma comment(lib,"dll.lib")
#include "A.h"
..................
dll d;
LPCTSTR b=d.Fun();

error,why
thank:)

Look up c_str() function.

try this

LPCTSTR lpszStr=(LPCTSTR)Rxg;

>>LPCTSTR b=d.Fun();

post the complete error message, I don't think you exported/imported the function correctly. This is a macro I use. When compiling the DLL, define the macro MYEXPORT, when compiling the application then do not define it.

#ifdef MYEXPORT
#define DllExport  __declspec( dllexport )
#else
#define DllExport  __declspec( dllimport )
#endif

class AFX_NOVTABLE dll 
{
public:
DllExport LPCTSTR Fun();
};

thank you:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.