這裏是我的代碼部分:副本的char *爲char *
extern "C" REGISTRATION_API int extreme(char* lKey)
{
string s1;
char *p=NULL;
try
{
ifstream myfile ("extreme.txt");
int i=0;
if (myfile.is_open())
{
while (getline(myfile,s1))
{
switch (i)
{
case 1:
strcpy(p,s1.c_str());
lKey=p;
break;
//continue here
}
}
}
}
現在,當我打電話從外部應用這個功能,我得到這個錯誤:
AccessViolationException:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
的問題是由於這樣的:
lKey=p;
我如何分配給lKey
p
?
你在哪裏分配內存到指針p? – 2010-07-15 14:29:05