Expected a declaration

kaveh rahimi 61 Reputation points
2021-09-21T14:33:32.75+00:00

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++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,787 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 118.5K Reputation points
    2021-09-21T16:07:38.117+00:00

    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";
    }
    
    0 comments No comments

  2. Minxin Yu 12,251 Reputation points Microsoft Vendor
    2021-09-22T02:21:35.863+00:00

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.