question

kavehrahimi-5744 avatar image
0 Votes"
kavehrahimi-5744 asked juhapartanen-5030 commented

Expected a declaration

Hi , I debug the code below:

include <windows.h>

include <iostream>


 typedef        VOID(CALLBACK    * mPCH341_NOTIFY_ROUTINE) (  // É豸ʼþ֪ͨ»Øµ÷³ÌÐò
     ULONG            iEventStatus);  // É豸ʼþºÍµ±Ç°×´Ì¬(ÔÚÏÂÐж¨Òå): 0=É豸°Î³öʼþ, 3=É豸²åÈëʼþ

define CH341_DEVICE_ARRIVAL 3 // É豸²åÈëʼþ,ÒѾ­²åÈë

define CH341_DEVICE_REMOVE_PEND 1 // É豸½«Òª°Î³ö

define CH341_DEVICE_REMOVE 0 // É豸°Î³öʼþ,ÒѾ­°Î³ö




 BOOL    WINAPI    CH341SetDeviceNotify(
     ULONG                    iIndex,
     PCHAR                    iDeviceID,
     mPCH341_NOTIFY_ROUTINE    iNotifyRoutine);
 if (CH341SetDeviceNotify(
     ULONG                    iIndex,
     PCHAR                    iDeviceID,
     mPCH341_NOTIFY_ROUTINE    iNotifyRoutine) == 1) {
     cout << "usb port connected";
 }

And receive the error E0169 which concerns the line of 'if' statement.How can I fix it?
Please help
Thanks

c++
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Lines 1-4 constitute a declaration of the function CH341SetDeviceNotify. The purpose of the declaration is to inform the compiler about the number of parameters, the type of each, and the type of the return value. While they do not cause a problem, the compiler will ignore the names you gave to the parameters.

Lines 5-8 constitute an attempt to call the function. When calling a function, you specify the value of the arguments BUT not their type. Each argument will be checked against the type already specified in the declaration and converted if necessary to match that type.

In shorthand, a function declaration has the form
return_type function_name(type, type, type);
and call of that function has the form
function_name(value, value, value);

0 Votes 0 ·

If attached source code is from project with header info (snap):

// ...
// DLL for USB interface chip CH341
// C, VC5.0
//...

you sure noticed that (C/VC5.0) code is written for OS versions before Vista. Are these your target OS or are you trying to compile for newer versions of Windows?

0 Votes 0 ·
Viorel-1 avatar image
0 Votes"
Viorel-1 answered

CH341SetDeviceNotify is a function that requires three arguments. For example:

 void CALLBACK MyNotifyRoutine( ULONG iEventStatus )
 {
     //
 }
    
 . . . .
    
 ULONG iIndex = 0; // probably it is zero
 PCHAR iDeviceID = ???; // use the device's ID
 mPCH341_NOTIFY_ROUTINE iNotifyRoutine = &MyNotifyRoutine;
    
 if (CH341SetDeviceNotify( iIndex, iDeviceID, iNotifyRoutine)) 
 {
      cout << "done";
 }

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MinxinYu-MSFT avatar image
0 Votes"
MinxinYu-MSFT answered MinxinYu-MSFT edited

Hi, kavehrahimi-5744

The error E0169:



    if (CH341SetDeviceNotify(
          ULONG                    iIndex,
          PCHAR                    iDeviceID,
          mPCH341_NOTIFY_ROUTINE    iNotifyRoutine) == 1) {
          cout << "usb port connected";
      }

if(CH341SetDeviceNotify()) should be used in main() or other function.
The function needs to be defined and requires three arguments as Viorel-1 said.
By the way, cout needs to be changed to std::cout.

Best regards,

Minxin Yu


If the response is helpful, please click "Accept Answer" and upvote it.


Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, @kavehrahimi-5744
May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

0 Votes 0 ·