[C++]Question with calling

Discussion in 'Mixed Languages' started by stevemk14ebr, Dec 24, 2012.

  1. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #1 stevemk14ebr, Dec 24, 2012
    Last edited by a moderator: Apr 20, 2017
    First i'll just show a segment of the code
    Code:
    int main()
    {
    loop();//start the loop checking for keys
    return 0;
    }
    void unhook()
    {
    UnhookWindowsHookEx(unhk);
    
    }
    int hook()
    {
    int argc;
    char **argv;
    HANDLE hThread;
    DWORD dwThread;
    
    hThread = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)
    TheKeyLogger, (LPVOID) argv[0], NULL, &dwThread);
    hkd=TRUE;//set variable hkd to true
    if (hThread)
    return WaitForSingleObject(hThread,INFINITE);
    else return 1;
    }
    void loop()
    {
    if (GetAsyncKeyState(VK_F5) && hkd==FALSE)
    {
     hook();
    }
    else if (GetAsyncKeyState(VK_F5) && hkd==TRUE)
    {
    unhook();
    }
    
    }
    it's a port of a vb.net program i wrote, in my vb program i call between subs (subs are hook, and unhook)
    but when i do this in c++ i get various errors
    in vb.net i would do this
    Code:
    public sub hook()
    'hooks stuff
    End Sub
    
    Public sub Loop()
    call hook()
    end sub
    how do i do this in c++ (im also confused on when to use int,or void, i've learned c++ in about 2 days so give me a break)
     
  2. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    fixed it had to move main below loop
     
  3. master131

    master131 MDL Novice

    Apr 12, 2011
    45
    22
    0
    I'm not sure what exactly you are trying to achieve, but maybe you should go read some C++ tutorials. In C++, it matters in which order functions are placed in a .cpp file (unlike VB.NET) because it reads the code from top to bottom. You should place main at the bottom because it depends on hook and unhook.
     
  4. Pr3acher

    Pr3acher MDL Member

    Aug 24, 2012
    143
    48
    10
    Ok but we are not obliged if we set prototypes?
     
  5. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    i was just playing around with c++, i'm not seriously involved in it i'm just learning by experience, like how i did with vb.net
     
  6. master131

    master131 MDL Novice

    Apr 12, 2011
    45
    22
    0
    Yes, there's also function prototypes too.

    Fair enough then.