我在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 :(得分:4)
它无效,因为您的项目中没有MFC支持。
您最好的解决方案是重新启动,让您的项目成为MFC DLL的开头并复制您的代码。
如果失败,您可以在项目设置中添加MFC支持&gt;链接&gt;一般&gt; Use MFC in a static/shared library
。
还需要:在stdafx.h中注释掉#include <windows.h>
并添加
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
然后你面临的问题是你有两个DllMain()
函数 - 一个在你的dll中,一个在MFC内部。注释掉你的dll中的那个(虽然你的要求可能会有所不同。请参阅此处的进一步阅读:error LNK2005: _DllMain@12 already defined in MSVCRT.lib)
如果您只是为CString支持而这样做,那么请不要这样做。而是仅使用std :: string。