熟悉delphi和visual c++的高手请进!如何在C中将delphi的纪录写到文件中去!我在delphi中定义:type
PForumInforStruct = ^TForumInforStruct;
TForumInforStruct = record
Column : string;
Date : string;
title : string;
Author : string;
IDNum : string;
Content : string;
end; 然后function test(): string;
var
...(省去偌干代码)
Handle : THandle;
hstWriteStructToFile: ThstWriteStructToFile;
ForumInforStruct: TForumInforStruct;
begin
...(省去偌干代码) len := length(string(@ForumInforStruct));
{ Win32File.dll”的文件映象映射进调用进程的地址空间 }
Handle:=LoadLibrary(PChar(HST_WIN32_FILE_DLL_NAME));
if Handle<>0 then
begin
{ 取得DLL中函数hstShowMessage()的地址 }
@hstWriteStructToFile := GetProcAddress(Handle,'hstWriteStructToFile');
if (@hstWriteStructToFile<>nil) then
begin
hstWriteStructToFile(PChar(@ForumInforStruct), len, PChar(FileName));
end;
{ 从进程的地址空间中解除“hstWriteStructToFile.dll”文件的映射 }
FreeLibrary(Handle);
end;
end;这段代码事不是有什么问题呢?vc中定义extern "C" __declspec(dllexport) int hstWriteStructToFile(char *pStruct, int len, char *FileName)
{
FILE *fp;
char *ptr;
int count;
count = 0;
ptr = pStruct;
fp = fopen(FileName, "wb+");
if(fp == NULL)
{
return -1;
}
/*********************************************
这里如何将pStruct所指向的结构变量写道文件里去呢?
如何判断delphi纪录的结束呢?
我知道如果在vc中也定义一个结构相同结构变量,然后强制转换就可以(我做过了)
但是如果仅仅靠指针能不能完成这认务呢?
*********************************************/
fclose(fp);
return 0;
}
PForumInforStruct = ^TForumInforStruct;
TForumInforStruct = record
Column : string;
Date : string;
title : string;
Author : string;
IDNum : string;
Content : string;
end; 然后function test(): string;
var
...(省去偌干代码)
Handle : THandle;
hstWriteStructToFile: ThstWriteStructToFile;
ForumInforStruct: TForumInforStruct;
begin
...(省去偌干代码) len := length(string(@ForumInforStruct));
{ Win32File.dll”的文件映象映射进调用进程的地址空间 }
Handle:=LoadLibrary(PChar(HST_WIN32_FILE_DLL_NAME));
if Handle<>0 then
begin
{ 取得DLL中函数hstShowMessage()的地址 }
@hstWriteStructToFile := GetProcAddress(Handle,'hstWriteStructToFile');
if (@hstWriteStructToFile<>nil) then
begin
hstWriteStructToFile(PChar(@ForumInforStruct), len, PChar(FileName));
end;
{ 从进程的地址空间中解除“hstWriteStructToFile.dll”文件的映射 }
FreeLibrary(Handle);
end;
end;这段代码事不是有什么问题呢?vc中定义extern "C" __declspec(dllexport) int hstWriteStructToFile(char *pStruct, int len, char *FileName)
{
FILE *fp;
char *ptr;
int count;
count = 0;
ptr = pStruct;
fp = fopen(FileName, "wb+");
if(fp == NULL)
{
return -1;
}
/*********************************************
这里如何将pStruct所指向的结构变量写道文件里去呢?
如何判断delphi纪录的结束呢?
我知道如果在vc中也定义一个结构相同结构变量,然后强制转换就可以(我做过了)
但是如果仅仅靠指针能不能完成这认务呢?
*********************************************/
fclose(fp);
return 0;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货