下面是VC:
typedef struct plog
{
int log_id;//记录编号
char userName[20];//使用者
char ip[20];//使用IP
char content[50];//日志内容
}plog;//添加使用记录
extern "C" __declspec(dllexport) void createLog(plog log);delphi:
TDBPlog = record
  log_id:Integer;//记录编号
  userName:array[0..19] of Char;//使用者
  ip:array[0..19] of Char;//使用IP
  content:array[0..49] of Char;//日志内容
end;
PDBPlog = ^TDBPlog;TDBCreateLog = procedure(log:TDBPlog);stdcall;procedure TForm1.btn1Click(Sender: TObject);
var
  FDllHandle:HMODULE;  
  FCreateLog:TDBCreateLog;
  plog:TDBPlog;
begin
  FDllHandle := LoadLibrary('proxyData.dll');
  if FDllHandle = 0 then raise Exception.Create('数据库 DLL 加载失败');
  FCreateLog := GetProcAddress(FDllHandle,'createLog');
  plog.userName := '11';
  plog.ip := '192.168.1.199';
  plog.content := 'test';
 FCreateLog(plog); //数据有插入数据库  
end;//单击事件结束后提示出错

解决方案 »

  1.   

    vc的dll中函数是这样的:
    extern "C" __declspec(dllexport) void createLog(plog log)
    {
    CString log_ip;
    CString user_name;
    CString content;
    log_ip.Format("%s",log.ip);
    user_name.Format("%s",log.userName);
    content.Format("%s",log.content);
    CTime t_Now;
    t_Now=CTime::GetCurrentTime();
    CString s_Now=t_Now.Format("%Y-%m-%d %H:%M:%S");
    CString sql = "insert into sys_log(log_ip,log_time,user_name,content)values('"+log_ip+"','"+s_Now+"','"+user_name+"','"+content+"')";
    exequery(sql);}
      

  2.   

    TDBCreateLog = procedure(log:TDBPlog);cdecl;
      

  3.   

    FCreateLog(plog^); //数据有插入数据库  
      

  4.   

    谢谢,那个方法正确了,但是其它我也改成cdecl还是出错?比如:
    vc:
    typedef struct midserver
    {
    int s_id;//服务器编号
    char s_ip[20];//服务器IP地址
    char s_province[20];//服务器所在省份
    char s_city[20];//服务器所在城市
    char s_area[20];//服务器所在区域
    int status;
    }midserver;extern "C" __declspec(dllexport) void queryMidServer(midserver* mids)
    {
    if(isconn)
    {
    CString sql = "select * from sys_middle_server where status=0";
    if(mysql_real_query(&mysql,(char*)(LPCTSTR)sql,(UINT)sql.GetLength())==0)
    { MYSQL_RES *result;
    MYSQL_ROW row;
    if((result=mysql_use_result(&mysql)))

    while(row=mysql_fetch_row(result)){ if(row[0]!=NULL)
    {
    mids->s_id=atoi(row[0]);
    } if(row[1]!=NULL)
    {
    sprintf(mids->s_ip,row[1]);
    } if(row[3]!=NULL)
    {
    sprintf(mids->s_province,row[3]);
    } if(row[2]!=NULL)
    {
    mids->status=atoi(row[2]);
    } if(row[4]!=NULL)
    {
    sprintf(mids->s_city,row[4]);
    } if(row[5]!=NULL)
    {
    sprintf(mids->s_area,row[5]);
    } mids++;
    } }
    }

    }}
    delphi:TDBCenterServer = record
          s_id:Integer;//服务器编号
          s_ip:array[0..19] of Char;//服务器IP地址
          s_province:array[0..19] of Char;//服务器所在省份
          s_city:array[0..19] of Char;//服务器所在城市
          s_area:array[0..19] of Char;//服务器所在区域
          status:Integer;
        end;
        PDBCenterServer = ^TDBCenterServer;
    procedure TForm1.btn1Click(Sender: TObject); 
    var 
      FDllHandle:HMODULE;  
      
     cs:TDBCenterServer;
    begin 
      FDllHandle := LoadLibrary('proxyData.dll'); 
      if FDllHandle = 0 then raise Exception.Create('数据库 DLL 加载失败'); 
      FQueryCenterServer := GetProcAddress(FDllHandle,'queryMidServer');
      FQueryCenterServer(@cs);
    end;//单击事件结束后提示出错