§§一个Delphi写的DLL,我在VC中调用,出错§为什么?§§
 
Delphi中定义是:
procedure  EncryptString(str : shortstring; sel : integer); Stdcall;
我在vc中这么用:
HINSTANCE     dllInstance;
dllInstance=::LoadLibrary(_T("Encrypt.dll"));
if(dllInstance==NULL)
{
AfxMessageBox("Can't open dll file");
}    
typedef void(__stdcall *MYFUN)(char *,int);
MYFUN StrChang;
StrChang=(MYFUN)GetProcAddress(dllInstance,"EncryptString");
if(StrChang== NULL) 
{
AfxMessageBox("Can't find function");
}
else
{
// 开始转换,StrChang
char *szstr= "中华人民共和国";
StrChang( szstr, 3 );
}执行到StrChang时出错:
  Unhandled exception in Encrypt.exe: 0xc000005:access Violation!

解决方案 »

  1.   

    shortstring 在VC中不能识别,改用PChar便可以。
      

  2.   

    to  jiadrun(MustBeSuccess):
      怎么改,谢谢
      

  3.   

    procedure  EncryptString(str : shortstring; sel : integer); Stdcall;
    改为:
    procedure  EncryptString(str : PChar; sel : integer); Stdcall;
      

  4.   

    to jiadrun(MustBeSuccess) 
       但是我没有delphi的源程序呀,改不了他的定义!
      

  5.   

    shortstring 的结构和BSTR差不多你可以试一试
      

  6.   

    Type          Maximum length Memory required Used for
    ShortString 255 characters 2 to 256 bytes backward compatibility如果是这样(不能改DLL),此DLL只能用于Delphi程序。
    不过可以再用Delphi封装一次此函数,改用PChar类型。
      

  7.   

    jiadrun(MustBeSuccess)的方法可行
      

  8.   

    VC和Delphi下的字符串类型是不兼容的。