Answered How to call c function in C++?

  • Tuesday, March 13, 2012 1:26 AM
     
      Has Code

    Hi,

    I have a c header file in C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\UIAutomation.h. I want to call a function ElementFromPoint in my C++ app. I have written below code

    #include "stdafx.h"
    #include "afxwinappex.h"
    #include "afxdialogex.h"
    #include "FirstMFCApplication.h"
    #include "MainFrm.h"
    #include <UIAutomation.h>
    #include <UIAutomationClient.h>
    #include <UIAutomationCore.h>
    #include <UIAutomationCoreApi.h>
    #include <WinDef.h>
    #include <Windows.h>
    #include "FirstMFCApplicationDoc.h"
    #include "FirstMFCApplicationView.h"
    
    extern "C" HRESULT ElementFromPoint([in] POINT pt, [out, retVal IUIAutomationElement **element);

    But when i compile i am getting below errors.

    Error 1 error C3115: 'in': this attribute is not allowed on 'pt' d:\tutorial\c++\firstmfcapplication\firstmfcapplication\firstmfcapplication.cpp 230 1 FirstMFCApplication
    Error 2 error C2337: 'retVal' : attribute not found d:\tutorial\c++\firstmfcapplication\firstmfcapplication\firstmfcapplication.cpp 230 1 FirstMFCApplication
    Error 3 error C2146: syntax error : missing ']' before identifier 'IUIAutomationElement' d:\tutorial\c++\firstmfcapplication\firstmfcapplication\firstmfcapplication.cpp 230 1 FirstMFCApplication
    Error 4 error C2061: syntax error : identifier 'IUIAutomationElement' d:\tutorial\c++\firstmfcapplication\firstmfcapplication\firstmfcapplication.cpp 230 1 FirstMFCApplication

    I doubt my syntax is correct and that UIAutomation.h is actually a c header. I just want to call some of the c functions in my C++ app. Please help.

    Thanks,

    Pratap


    • Edited by Pratap15 Tuesday, March 13, 2012 2:22 AM
    •  

All Replies

  • Tuesday, March 13, 2012 3:15 AM
     
     Answered

    Pratap15 wrote:

    I have a c header file in C:\Program Files\Microsoft  SDKs\Windows\v7.0A\Include\UIAutomation.h. I want to call a function
    ElementFromPoint in my C++ app. I have written below code

    extern "C" HRESULT ElementFromPoint([in] POINT pt, [out, retVal  IUIAutomationElement **element);

    If you are talking about this:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ee671538.aspx

    then ElementFromPoint is not a C nor a C++ function, but a COM interface  method. You have to first create a CUIAutomation object, then call a  method on this object.

    You might want to study this sample:

    http://code.msdn.microsoft.com/windowsdesktop/UI-Automation-Document-24a3 7c82

    I doubt my syntax is correct

    Your doubt is well founded.


    Igor Tandetnik

    • Marked As Answer by Pratap15 Tuesday, March 13, 2012 4:52 AM
    •