如题。主程序在vc中编译通过,运行时出错
如果主程序用(qt)MinGW编译就能正常使用。
是不是文本编码的问题?如何解决?
dll 代码
#include <string>
using namespace std;
//extern "C" __declspec(dllexport) string token(string ss, char a)
__declspec(dllexport) string token(string ss, char a)
{ string s=ss;
int l;
l=s.length();
int i=0;
while (i<l)
{ if ( s [ i ] ==a) { s=s.substr(0,i); break; }
i++; }
return s;
}
主程序代码
#include <windows.h>
#include <iostream>
#include<string>
#include<fstream>
#include<stdio.h>
using namespace std;
typedef string (*token_func_t) (string ss,char a);
int main(int argc, CHAR* argv[])
{// 加载DLL
HINSTANCE hInst = LoadLibrary("str.dll");
if (hInst == 0)
{cout<<"no dll found!";}
else{
token_func_t token = (token_func_t)GetProcAddress(hInst,"token");
cout<<token("abcd",'c');
}
int var;
cin >> var;
}