2012-12-28 16 views
0

我在visual c++ 6.0中創建了Win 32 dynamic link library項目,而我編寫了下面的代碼,它在編譯時顯示了一些錯誤。無法在Visual c + + 6.0中使用字符串格式

for(i = 0; i < (int) len; i++) 
{ 
strTmp.Format("%C", m_Track1Buffer[i]); 
strASCII += strTmp; 
} 

當我編譯上面的代碼顯示了我以下錯誤:

error C2228: left of '.Format' must have class/struct/union type 

我有包括以下在我的代碼header files

#include <string.h> 
#include <cstring> 
#include <iostream> 
#include "stdafx.h" 
#include <stdio.h> 
#include <String.h> 
#include <mmsystem.h> 
#include <winsock2.h> 
#include <windows.h> 

除了請告訴我爲什麼我不能在上述項目中使用CString。我還包括alstr.h,但它並沒有幫助我。

+0

當你問一個15歲的編譯器的問題時,你需要發佈更好的repro代碼。最好的猜測是你只是忘了聲明strTmp。 –

+0

顯然你沒有將strTmp聲明爲正確的類型 - 但是你沒有發佈該代碼,所以我們無法提供幫助。 – Hogan

回答

3

這不起作用,因爲您的項目中沒有MFC支持。

你最好的解決方案是通過使你的項目的MFC DLL先從再次啓動,並複製你的代碼中。

如果做不到這一點,你可以在項目設置>連接>常規>Use MFC in a static/shared library添加MFC支持。

還要求:在stdafx.h中註釋掉#include <windows.h>並添加

#include <afxwin.h>   // MFC core and standard components 
#include <afxext.h>   // MFC extensions 

那麼你面臨的問題是,你有兩個DllMain()功能 - 一個在你的DLL和一個在MFC內部。註釋掉你的dll中的一個(雖然你的需求可能不同,請參閱:error LNK2005: [email protected] already defined in MSVCRT.lib

如果你只是爲了CString支持而做的,那就不要這樣做。相反,只需使用std :: string。