在非MFC環境中使用CString、使用_bstr_t

項目屬性-》常規-》在共享 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;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章