Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Sep : String[] to C struct

www.cryer.info
Managed Newsgroup Archive

String[] to C struct

Subject:String[] to C struct
Posted by:"Devinder Verman" (verman..@hotmail.com)
Date:28 Sep 2007 06:34:04 -0700

Hi,
  I have to interface with C DLL. At some places I have used String[128]
type to keep my strings within 128 char limit. The size of this type is 129
bytes, as [0] is used to store the length of string in variable. Now if I
use
typedef struct{
   unsigned char len;
   char str[128];
} String128;
in C. I cannot pass a record into this String[128] . My application
crashes. The DLL uses stdcall mechanism.

Delphi:
type
        String128 = String[128];
Procedure DataFromC(s : String128); stdcall;
begin
        // my code to process s and store it.
end;

C:
struct defined as above
typedef void (__stdcall *ProcDataFromC)(String128 instr);

String128 s;
s.len = 10;
strncpy(s.str,"Testing len chars", s.len); // Get only s.len chars
ProcDataFromC DataFromC = (ProcDataFromC)GetProcAddress(hDelphiApplication,
"DataFromC");
if (DataFromC)
   DataFromC(s);

Could someone explain why this is not working and how to fix it. Thanks

DP

Info

Glossary

File Types

Replies:

www.cryer.info
Managed Newsgroup Archive