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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nort clear on structure use and createThread external function call.

Status
Not open for further replies.

pecan204

Programmer
Jan 25, 2001
24
0
0
US
I am not real clear on using structure statements and external function calls. I am getting the following errors when I compile the file below. Can someone hlep? Thanks.

cinterface3.cpp(22) : error C2228: left of '.start' must have class/struct/union type
cinterface3.cpp(24) : error C2664: 'CreateThread' : cannot convert parameter 3 from 'void (long *)' to 'unsigned long (__stdcall *)(void *)'
cinterface3.cpp(30) : error C2228: left of '.time' must have class/struct/union type

#include
#include
#include

struct io {
char time[10];
int start;
};

struct io cio;

extern "C" __declspec(dllimport) void _stdcall FTREND3
( long * );

void main (void)
{
DWORD tid, cio;

HANDLE hThread;

cio.start = 1;

hThread = CreateThread(NULL, 0, FTREND3, &cio, 0, &tid);
CloseHandle(hThread);

printf("In c after fortran thread started\n\n");
printf("string = %s\n",cio.time);
}
 
Well, you declared cio right once, but then you shadowed it in main by declaring a DWORD called cio there, too. That means it's using the DWORD instead of the struct io object. That takes card of the first and third errors.

The second error just says it wants a function that returns void and takes a void*. You gave it a function that returns void and takes a long*. Almost, but not quite. Change the daclaration of the function and probably do a cast from void* to long* in the definition and you should be good.
 
Thanks chipper,
I just added the prototype below based on a suggestion. When I comment it out it compiles and links and when not it has a link error. Not sure if it is correct.

DWORD WINAPI FTREND3(LPVOID);

Where I am not clear in the createThread function is if it actually passes the integer to the integer function or does it just launch it and the integer function then see the shared memory of cio.start = 1 to start. And if the integer function return a value of 1 or 0 how is it then passed back through the createThread function for brought into the main c file?

Thanks for any help.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top