Expected a declaration

kaveh rahimi 61 Reputation points

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

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.
2,903 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 95,076 Reputation points

    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 4,986 Reputation points Microsoft Vendor

    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.