項目屬性-》常規-》在共享 DLL 中使用 MFC
#include "stdafx.h"
#include <string>
#include <comdef.h>
#include <atlstr.h>
void wlog(LPWSTR str)
{
FILE * fp = NULL;
setlocale(LC_ALL,"chs");
fp = fopen("C:\\log.txt", "a+" );
fwprintf( fp, str );
fwprintf( fp, L"\n" );
fclose(fp);
}
int _tmain(int argc, _TCHAR* argv[])
{
_bstr_t str = _bstr_t("1234");
CString cs = (LPCSTR)str;
LPWSTR lp = (LPWSTR)(LPCTSTR)cs;
wlog(lp);
system("pause");
return 0;
}