Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C to Delphi help

Status
Not open for further replies.

DjangMan

Programmer
Jun 1, 2001
1,785
CA
Hi all,

I'm trying to convert a C function into a Delphi function.

The function header is as follows:

__declspec( dllexport ) short BrainMain(const BrainInfo *brainInfo)

brainInfo is a record which I've set up with a type called TbrainInfo. I have two questions:

1) Is this the way to call the parameters for this function: function BrainMain(const BrainInfo TbrainInfo): smallint;

2) How do I call this function?
x:= BrainMain(?????);
Should I create a type that is a pointer to the record and pass that?

Regards,

DjangMan
 
If you are trying to call a DLL then its not as simple as what you have above.

Using LoadLibrary is one method of accessing DLLs (don't remember right now how to do it). You will need to look into this before writing the function.
Otherwise the only change is to make it like this:

function BrainMain(const BrainInfo: TbrainInfo): smallint;

When calling it, you have to pass it a parameter that has type TbrainInfo. How the DLL must be loaded and unloaded I don't remember.

Paul Winstone
paul.winstone@logicacmg.com
 
Hi Paul,

Thanks for the assistance.

The code I have in C is to create a DLL for a game (WinBolo to be exact). What I'm attempting to do is to create that DLL using Delphi so that why I'm trying to convert the code. My DLL is going to be called by the game.

Should my function be accepting a pointer to TbrainInfo (e.g. ^brainInfo) or the structure itself TbrainInfo?

Thanks,

DjangMan
 
If the structure is created within Delphi and you want to use that, then TBrainInfo is what you should use.
But as your C function declaration suggests you have a struct in there which defines it already, I would suggest trying a pointer to what the DLL contains. But I don't know if this will actually work. If you call it as a pointer in the finction (as per the C definition) then it may be all you need.
Assuming the DLL is properly loaded, I would expect this to work. Its been quite a while since I have done this so I might be wrong but this is how I would do it.

Paul Winstone
paul.winstone@logicacmg.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top