请问MFC如何传递CString数组参数?

worship668 2010-06-08 10:18:20
希望函数传递CString数组,可是在程序中遇到到问题
CString arrImages[100];
PrintImage(arrImages, theApp.m_nPrintMode);

BOOL WINAPI PrintImage(CString szImage[], BOOL bActual)
{
INT nValue=0,nUnit;
DOCINFO theDocInfo={sizeof(DOCINFO),_T("PrinterTarget"),NULL/*_T("C:\\a.tif")*/};
CImage theImage,theNew;
}

编译提示出错
error LNK2019: 无法解析的外部符号 "int __stdcall PrintImage(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > * const,int)" (?PrintImage@@YGHQAV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@H@Z),该符号在函数 "int __cdecl PrintImageFile(void *)" (?PrintImageFile@@YAHPAX@Z) 中被引用
1>D:\BSS_ALL\Debug\BookScanStation.exe : fatal error LNK1120: 1 个无法解析的外部命令

谢谢大家了先~
...全文
679 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
hcyang 2010-06-08
  • 打赏
  • 举报
回复
看样子PrintImage在一个DLL里,采用的是静态link.

在工程属性/link/input里,有追加依赖的lib文件吗?
wangli820 2010-06-08
  • 打赏
  • 举报
回复
传递MFC数组不要那么用
用 CStringArray 数组类代码
biosxjj 2010-06-08
  • 打赏
  • 举报
回复
去除WINAPI
yangzhenglun 2010-06-08
  • 打赏
  • 举报
回复
能传CString类型的值么? 要转换为char * 吧
biosxjj 2010-06-08
  • 打赏
  • 举报
回复
CString& szImage[],
一条晚起的虫 2010-06-08
  • 打赏
  • 举报
回复
// 看代码看不出有什么问题。
fangchao918628 2010-06-08
  • 打赏
  • 举报
回复
CString数组 cstringarray
worship668 2010-06-08
  • 打赏
  • 举报
回复
还是不太明白错在哪里了。。。太面了
一条晚起的虫 2010-06-08
  • 打赏
  • 举报
回复
Parameters
// FROM MSDN
hHandle [in]
A handle to the object. For a list of the object types whose handles can be specified, see the following Remarks section.

If this handle is closed while the wait is still pending, the function's behavior is undefined.

The handle must have the SYNCHRONIZE access right. For more information, see Standard Access Rights.

// Handle是你SetEvent的句柄。
worship668 2010-06-08
  • 打赏
  • 举报
回复
声明:BOOL WINAPI PrintImage(CString szImage[], BOOL bActual);
实现:BOOL WINAPI PrintImage(CString szImage[], BOOL bActual)
{
INT nValue=0,nUnit;
DOCINFO theDocInfo={sizeof(DOCINFO),_T("PrinterTarget"),NULL/*_T("C:\\a.tif")*/};
CImage theImage,theNew;
INT nWidth=GetDeviceCaps(ghDC,HORZRES);
INT nHeight=GetDeviceCaps(ghDC,VERTRES);
INT nRes=GetDeviceCaps(ghDC,LOGPIXELSX);
INT nBit=GetDeviceCaps(ghDC,BITSPIXEL);
}

先谢谢楼上的兄弟~
有问题吗?
一条晚起的虫 2010-06-08
  • 打赏
  • 举报
回复
// 打错了。
// 是指PrintImage()的声明和实现。
worship668 2010-06-08
  • 打赏
  • 举报
回复
BOOL PrintImageFile(void* pData)
{
CString arrImages[100];
if(!BeginPrint())
return FALSE;
INT nPage=::GetImageSize();
//for(INT nIndex=0;nIndex<theApp.m_nCopyCount;nIndex++)
//{
// for(INT iIndex=0;iIndex<nPage;iIndex++)
// {
// PrintImage(GetImagePath(iIndex),theApp.m_nPrintMode);
// }
//}
for(INT nIndex=0;nIndex<theApp.m_nCopyCount;nIndex++)
{
for(INT iIndex=0;iIndex<nPage;iIndex++)
{
arrImages[iIndex] = GetImagePath(iIndex);
}
}
PrintImage(arrImages, theApp.m_nPrintMode);
EndPrint();
return TRUE;
}

发现是这样,如果在PrintImageFile 掉用PrintImage(arrImages, theApp.m_nPrintMode);
就会出现这个错误,
worship668 2010-06-08
  • 打赏
  • 举报
回复
定义是这样的:
BOOL PrintImageFile(void* pData)
一条晚起的虫 2010-06-08
  • 打赏
  • 举报
回复
int __cdecl PrintImageFile(void *)"
// 是否定义和声明不一致?
oyljerry 2010-06-08
  • 打赏
  • 举报
回复
PrintImageFile函数定义和实现是否一致。注意WINAPI
klkvc386 2010-06-08
  • 打赏
  • 举报
回复
Mark.....
gwq85387566 2010-06-08
  • 打赏
  • 举报
回复
CString arrImages[100]={L"hello", L"gwq",L"111",L"hsdfsello",L"ggssdf"};
BOOL WINAPI PrintImage(CString** pArrayStr, BOOL bActual)
{
CString aImages[100];
memset(aImages, 0, sizeof(CString));
memcpy(aImages, pArrayStr, 100*sizeof(CString));
return TRUE;
}

PrintImage((CString**)&arrImages, TRUE);
hcyang 2010-06-08
  • 打赏
  • 举报
回复
看来大家都比较钟情CStringArray
但是用CStringArray尽量不要值传递
gmp00 2010-06-08
  • 打赏
  • 举报
回复
CStringArray,这是一个动态字符串数组,可以随时定义空间,不用专门释放很好用的

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧