Click to See Complete Forum and Search --> : Help with a compile error :)


gbrooks3
July 18th, 2006, 12:26 PM
Hi there, i am having a few problems with a program. I am just a rookie programmer and there are some things i dont understand, if you could help me, in simple terms it would be great :D

Firstly i have a compile error with a custom function:

error C2197: 'int (__cdecl *)(void)' : too many arguments for call

I am not sure how to rectify it all, and i am even more unsure they code will write the resource to the open com port...

void SendREDBoot (HANDLE com, HWND hWnd, int WriteCOMData())

{



LPBYTE lpData = NULL;

HRSRC hRsrc = FindResource( NULL, "CID00_EF_DVT", "Gen_Loader_Package");

DWORD dwSize = SizeofResource( NULL, hRsrc );

HGLOBAL hData = LoadResource( NULL, hRsrc );

lpData = (LPBYTE) ::LockResource(hData);

DWORD dwTimeout = 2000;

WriteCOMData(com, lpData, dwSize, dwTimeout);

}



Outside the function the code compiles, its just tidier this way i think. However, the resource is not sent. I think i need to include MAKEINTRESOURCE somehow?

Now, WriteCOMData() is a separate function. What i really think i need to do it give that function a handle and point to it, instead of redefining it in another function...or maybe that is total rubbish :(

Any help with making correct custom functions and defining them would be of great help :)

Thanks

gbrooks3
July 18th, 2006, 07:05 PM
Hi, Well i still cant compile the function, but in "open code" this does send the bin file i want to the comport:



LPBYTE lpData = NULL;

HRSRC hRsrc = FindResource( NULL, MAKEINTRESOURCE(CID00_EF_P3G),"LOADERS" );

DWORD dwSize = SizeofResource( NULL, hRsrc );

HGLOBAL hData = LoadResource( NULL, hRsrc );

lpData = (LPBYTE) ::LockResource(hData);

WriteCOMData(com, lpData, dwSize, dwTimeout);
UnlockResource( hRsrc );

FreeResource( hRsrc );




I now have two questions...


Unfortunatley there seems to be some kind of memory flaw in the code. Becuase the 42kb CID00_EF_P3G.bin wont send unless i cut it in half for example. I am not experienced enough with debugging so can someone guide me on how to increase the buffer size etc? :)
The bin file i want to send is to a device connected to a comport...however, throughout the sending of the file, the device should reply with a few bytes of data. At this point sending of the bin file should be paused and i need to send a 3 byte reply...then carry on with sending the rest of the bin file. This happens a number of times so i guess i must have to loop my Read function somehow?
Many thanks for the help :)

best.

philkr
July 19th, 2006, 05:22 AM
Concerning your compile problem: I assume you want to pass a function pointer as the third argument. In this case the right syntax is like this:
void SendREDBoot (HANDLE com, HWND hWnd, int (*WriteCOMData)(HANDLE,LPBYTE,DWORD,DWORD))
{
// ...
}

gbrooks3
July 19th, 2006, 09:49 AM
@philkr

Thats perfect, i understand the concept aswell which is even better :D Thanks :)

umm...i dont suppose you had a look at my two questions though? did you? I think its just a case of alocating a bigger buffer size, but i just dont know how.

Thanks for the help.

philkr
July 19th, 2006, 11:16 AM
umm...i dont suppose you had a look at my two questions though? did you? I think its just a case of alocating a bigger buffer size, but i just dont know how.
I can't tell without seeing the code of the function which writes to the com port.

gbrooks3
July 19th, 2006, 01:49 PM
Yes of course...sorry.

Write function:



int WriteCOMData(HANDLE f, unsigned char *lpBuffer, int nBufferSize, int dwMilliseconds)

{

DWORD NumberOfBytesTransferred = 0;

WriteFile(f, lpBuffer, nBufferSize, NULL, &m_OverlappedWrite);

DWORD res = WaitForSingleObject(m_EventWrite, dwMilliseconds);

if(res == WAIT_OBJECT_0) {

if(GetOverlappedResult(f, &m_OverlappedWrite, &NumberOfBytesTransferred, TRUE) == 0) {

MessageBox(NULL, "", "WRITE ERROR!", MB_ICONERROR);

}

}

return NumberOfBytesTransferred;

}



Read function:



int ReadCOMData(HANDLE f, unsigned char *lpBuffer, int nBufferSize, int dwMilliseconds)

{

DWORD NumberOfBytesTransferred = 0;

if(ReadFile(f, lpBuffer, nBufferSize, &NumberOfBytesTransferred, &m_OverlappedRead)) {

return NumberOfBytesTransferred;

} else if(GetLastError() == ERROR_IO_PENDING) {

switch(WaitForSingleObject(m_EventRead, dwMilliseconds)) {

case WAIT_OBJECT_0:

NumberOfBytesTransferred = 0;

if(GetOverlappedResult(f, &m_OverlappedRead, &NumberOfBytesTransferred, FALSE) == 0) {

MessageBox(NULL, "", "READ ERROR!", MB_ICONERROR);

}

return NumberOfBytesTransferred;

default:

PurgeComm(f, PURGE_RXABORT);

}

} else {

MessageBox(NULL, "", "READ ERROR!", MB_ICONERROR);

}

return 0;

}



int ReadCOMBytes(HANDLE f, unsigned char *lpBuffer, int nBufferSize, int dwMilliseconds)

{

int iTransferred = 0;

int iRead = 0;

while((iTransferred < nBufferSize) && (iRead = ReadCOMData(f, &lpBuffer[iTransferred], nBufferSize - iTransferred, dwMilliseconds)) != 0)

{

iTransferred += iRead;

}

return iTransferred;

}



(I dont mean to take advantage of your good will but i also have a problem when reading (ReadCOMBytes) after writing the bin files. The prgram just exits and no bytes are read. :(

Anyway, any help you can give will be great, i just want to learn from you guys :)