To greensoft(一个学习很棒的初中生。) :来我的贴子里发广告,交保护费了么?回答你,当然先学windows编程了,消息机制怎么可以不看?不过我觉得你先把中考忙完了再说其它:)。
To eggplant(拉拉)兄: /*------------------------------*/ 你可以通过参数返回值,在VB中分配空间,然后把空间指针作为参数传递给函数,这样便于管理空间,不容易发生内存泄漏。void WINAPI gets(LPSTR pch) { sprintf(pch,"%s", "hehe"); } /*------------------------------*/ 这么做了,可是编译报错:'void __stdcall gets(char *)' --------------------Configuration: testdllmfc1 - Win32 Debug-------------------- Compiling... testdllmfc1.cpp D:\Documents and Settings\Administrator\桌面\testdllmfc1\testdllmfc1.cpp(86) : error C2556: 'void __stdcall gets(char *)' : overloaded function differs only by return type from 'char *__cdecl gets(char *)' d:\program files\microsoft visual studio\vc98\include\stdio.h(324) : see declaration of 'gets' D:\Documents and Settings\Administrator\桌面\testdllmfc1\testdllmfc1.cpp(86) : error C2373: 'gets' : redefinition; different type modifiers
d:\program files\microsoft visual studio\vc98\include\stdio.h(324) : see declaration of 'gets' D:\Documents and Settings\Administrator\桌面\testdllmfc1\testdllmfc1.cpp(86) : error C2491: 'gets' : definition of dllimport function not allowed Error executing cl.exe.testdllmfc1.dll - 3 error(s), 0 warning(s)
不好意思,原来和C语言重名了呀。编译通过,但运行报错:string!=NULLvoid WINAPI gets(LPSTR pch) { sprintf(pch,"%s", "hehe"); } /*------------------------------*/Dim teststr As StringPrivate Sub Command3_Click() getstr (teststr) MsgBox teststr End Sub
该成/*------------------------------*/Dim teststr As StringPrivate Sub Command3_Click()teststr="0000000000000000"getstr (teststr) MsgBox teststrEnd Sub就没事了!在VB中分配空间,只能这么干么? teststr="0000000000000000"代码太不像话,怎么该好?
MsgBox gets()LPSTR WINAPI WINAPI gets()
{
return "hehe";
}运行中报错
string!=NULL
BOOL __stdcall GetFileTimer(LPCTSTR filename,void *ptime)
{
HANDLE hfile;//定义的存放文件句柄
SYSTEMTIME lt;//标准系统时间结构变量
FILETIME createtime,accesstime,lastwritetime;
//获得文件句柄只能用这种方式,有时可以用FileOpen()得HFILE型句柄
hfile=::CreateFile(filename,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_READONLY,0);
::GetFileTime(hfile,&createtime,&accesstime,&lastwritetime);
::FileTimeToSystemTime(&lastwritetime,<);
short * npTime = ( short * ) ptime;
//int nTemp = ;
npTime[0]=lt.wYear;
npTime[1]=lt.wMonth ;
npTime[2]=lt.wDay;
npTime[3]=(lt.wHour+8)%24;
npTime[4]=lt.wMinute ;
npTime[5]= lt.wSecond ;/* memcpy ( npTime, & nTemp, sizeof ( int ) );
npTime ++;
nTemp = lt.wMonth ;
memcpy ( npTime, & nTemp, sizeof ( int ) );
nTemp = lt.wDay;
npTime ++;
memcpy ( npTime, & nTemp, sizeof ( int ) );
nTemp = lt.wHour;
npTime ++;
memcpy ( npTime, & nTemp, sizeof ( int ) );
nTemp = lt.wMinute ;
npTime ++;
memcpy ( npTime, & nTemp, sizeof ( int ) );
nTemp = lt.wSecond ;
*/
return TRUE;
}
{
sprintf(pch,"%s", "hehe");
}
/*------------------------------*/
你可以通过参数返回值,在VB中分配空间,然后把空间指针作为参数传递给函数,这样便于管理空间,不容易发生内存泄漏。void WINAPI gets(LPSTR pch)
{
sprintf(pch,"%s", "hehe");
}
/*------------------------------*/
这么做了,可是编译报错:'void __stdcall gets(char *)'
--------------------Configuration: testdllmfc1 - Win32 Debug--------------------
Compiling...
testdllmfc1.cpp
D:\Documents and Settings\Administrator\桌面\testdllmfc1\testdllmfc1.cpp(86) : error C2556: 'void __stdcall gets(char *)' : overloaded function differs only by return type from 'char *__cdecl gets(char *)'
d:\program files\microsoft visual studio\vc98\include\stdio.h(324) : see declaration of 'gets'
D:\Documents and Settings\Administrator\桌面\testdllmfc1\testdllmfc1.cpp(86) : error C2373: 'gets' : redefinition; different type modifiers
d:\program files\microsoft visual studio\vc98\include\stdio.h(324) : see declaration of 'gets'
D:\Documents and Settings\Administrator\桌面\testdllmfc1\testdllmfc1.cpp(86) : error C2491: 'gets' : definition of dllimport function not allowed
Error executing cl.exe.testdllmfc1.dll - 3 error(s), 0 warning(s)
{
sprintf(pch,"%s", "hehe");
} /*------------------------------*/Dim teststr As StringPrivate Sub Command3_Click()
getstr (teststr)
MsgBox teststr
End Sub
MsgBox teststrEnd Sub就没事了!在VB中分配空间,只能这么干么?
teststr="0000000000000000"代码太不像话,怎么该好?