dll函数返回字符串问题。

bgtjing 2004-08-17 03:22:20
我是一个初学者,想问如下问题:
1、下面代码中有什么问题:为何我在pb中调用只能调用一次。
static char* g_Fonts= new char[200];
int CALLBACK EnumFontsProc(
CONST LOGFONT *lplf, // logical-font data
CONST TEXTMETRIC *lptm, // physical-font data
DWORD dwType, // font type
LPARAM lpData// application-defined data
)
{
strcat(g_Fonts,(char*)lplf->lfFaceName);
strcat(g_Fonts,(char*)",");
return 1;
}
extern "C" _declspec ( dllexport )
char* pascal getfonts()
{
strcpy(g_Fonts,"");
EnumFontFamilies(GetDC(NULL),NULL,(FONTENUMPROC)EnumFontsProc,0);
return g_Fonts;
}
2、dll函数参数中可以引用数组吗?如何做:
...全文
151 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanglin559 2004-08-21
  • 打赏
  • 举报
回复
我也遇到了这个问题
holyeagle 2004-08-17
  • 打赏
  • 举报
回复
g_Fonts= new char[200];会不会太小,你一直在用strcat,可能会越界。建议动态分配,

if (g_strSize <= (strlen(g_Fonts)+strlen(lplf->lfFaceName))
{
g_strSize += 4096;
char* ptemp = new char[g_strSize];
// store old info
ZeroMemory(ptemp, g_strSize);
memcpy(ptemp, g_Fonts, strlen(g_Fonts));

delete []g_Fonts;
g_Fonts = ptemp;

}

./////do other
bgtjing 2004-08-17
  • 打赏
  • 举报
回复
是不是因为static char* g_Fonts没有释放内存?
bgtjing 2004-08-17
  • 打赏
  • 举报
回复
在进行调用就提示打开dll文件错误。
oyljerry 2004-08-17
  • 打赏
  • 举报
回复
1,只能调用一次,是什么意思?
2,dll参数中可以引用数组啊,可以传递数组的指针

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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