Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. In C# ,How can i use a C++ DLL with a class being defined in head file.

In C# ,How can i use a C++ DLL with a class being defined in head file.

Scheduled Pinned Locked Moved C#
questioncsharpc++
5 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dfbx
    wrote on last edited by
    #1

    i have a .h file like below. how can i use it in C#? //--------------------------------------------------------------- // AVEControl.h: interface for the AVEControl class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_AVECONTROL_H__4E171B4B_A11B_49F1_B41C_5F4A31B5CF08__INCLUDED_) #define AFX_AVECONTROL_H__4E171B4B_A11B_49F1_B41C_5F4A31B5CF08__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #ifdef DEVICECONTROL_EXPORTS #define DEVICECONTROL_API __declspec(dllexport) #else #define DEVICECONTROL_API __declspec(dllimport) #endif typedef HRESULT (*AVECALLBACK) (PBYTE pbData, LONG lDataLength); #define E_DEVICE_NOT_READY 0xB0004001L class DEVICECONTROL_API AVEControl { public: HRESULT StartRecordWithoutPreview(HWND hWndCap, CString FileName, __int64 pFileLength, UINT pFileMessage, BOOL pShowSetting = TRUE); HRESULT StartRecordWithPreview(HWND hWndCap, RECT rc, CString FileName, __int64 pFileLength, UINT pFileMessage, BOOL pShowSetting = TRUE); HRESULT StartPreview(HWND hWndCap, RECT rc); HRESULT SetVideoClippingWindow(HWND hwnd); HRESULT SetCallback(AVECALLBACK Callback); HRESULT GetVideoStatus(PUCHAR pSta); HRESULT SetVideoPosition(LPRECT lpSRCRect, LPRECT lpDSTRect); void GetCurrentImage(CString BmpFileFullName); BOOL IsGraphRunning(void); HRESULT StopGraph(void); HRESULT ApplySettings(CString IniFileFullName); HRESULT SetVideoProcAmp(long Property, long Value); HRESULT GetVideoProcAmp(long Property, long* Value); HRESULT GetEvent(long* EventCode, LONG_PTR* Param1, LONG_PTR* Param2, long msTimeout); HRESULT SetNotifyWindow(OAHWND hwnd, long lMsg, LONG_PTR lInstanceData); HRESULT InitDeviceControl(void); AVEControl(); virtual ~AVEControl(); }; #endif // !defined(AFX_AVECONTROL_H__4E171B4B_A11B_49F1_B41C_5F4A31B5CF08__INCLUDED_)

    A 1 Reply Last reply
    0
    • D dfbx

      i have a .h file like below. how can i use it in C#? //--------------------------------------------------------------- // AVEControl.h: interface for the AVEControl class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_AVECONTROL_H__4E171B4B_A11B_49F1_B41C_5F4A31B5CF08__INCLUDED_) #define AFX_AVECONTROL_H__4E171B4B_A11B_49F1_B41C_5F4A31B5CF08__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #ifdef DEVICECONTROL_EXPORTS #define DEVICECONTROL_API __declspec(dllexport) #else #define DEVICECONTROL_API __declspec(dllimport) #endif typedef HRESULT (*AVECALLBACK) (PBYTE pbData, LONG lDataLength); #define E_DEVICE_NOT_READY 0xB0004001L class DEVICECONTROL_API AVEControl { public: HRESULT StartRecordWithoutPreview(HWND hWndCap, CString FileName, __int64 pFileLength, UINT pFileMessage, BOOL pShowSetting = TRUE); HRESULT StartRecordWithPreview(HWND hWndCap, RECT rc, CString FileName, __int64 pFileLength, UINT pFileMessage, BOOL pShowSetting = TRUE); HRESULT StartPreview(HWND hWndCap, RECT rc); HRESULT SetVideoClippingWindow(HWND hwnd); HRESULT SetCallback(AVECALLBACK Callback); HRESULT GetVideoStatus(PUCHAR pSta); HRESULT SetVideoPosition(LPRECT lpSRCRect, LPRECT lpDSTRect); void GetCurrentImage(CString BmpFileFullName); BOOL IsGraphRunning(void); HRESULT StopGraph(void); HRESULT ApplySettings(CString IniFileFullName); HRESULT SetVideoProcAmp(long Property, long Value); HRESULT GetVideoProcAmp(long Property, long* Value); HRESULT GetEvent(long* EventCode, LONG_PTR* Param1, LONG_PTR* Param2, long msTimeout); HRESULT SetNotifyWindow(OAHWND hwnd, long lMsg, LONG_PTR lInstanceData); HRESULT InitDeviceControl(void); AVEControl(); virtual ~AVEControl(); }; #endif // !defined(AFX_AVECONTROL_H__4E171B4B_A11B_49F1_B41C_5F4A31B5CF08__INCLUDED_)

      A Offline
      A Offline
      Andrei Ungureanu
      wrote on last edited by
      #2

      you can try to create a DLL using the C++ class. After creating the DLL it's easier to use in c# with [DllImport] command. In c# char* becomes string byte* becomes byte[] and if you pass a value using reference like in your class "long* Value", use "ref log Value". Hope it helps Do your best to be the best

      D 1 Reply Last reply
      0
      • A Andrei Ungureanu

        you can try to create a DLL using the C++ class. After creating the DLL it's easier to use in c# with [DllImport] command. In c# char* becomes string byte* becomes byte[] and if you pass a value using reference like in your class "long* Value", use "ref log Value". Hope it helps Do your best to be the best

        D Offline
        D Offline
        dfbx
        wrote on last edited by
        #3

        the Question is not the data type. We can noticed that a class have been defined as below: { class DEVICECONTROL_API AVEControl } in the head file, all the functions is defined in the class. so if i use [DllImport] to define the function in C#, when run it, an exception is found ,which message as "EntryPoint can not be found in DLL", So I think the reason is that we cann't use the class from the unmanaged Dll directly in C#,we have to build a wrapper use C++.net . but How?

        A 1 Reply Last reply
        0
        • D dfbx

          the Question is not the data type. We can noticed that a class have been defined as below: { class DEVICECONTROL_API AVEControl } in the head file, all the functions is defined in the class. so if i use [DllImport] to define the function in C#, when run it, an exception is found ,which message as "EntryPoint can not be found in DLL", So I think the reason is that we cann't use the class from the unmanaged Dll directly in C#,we have to build a wrapper use C++.net . but How?

          A Offline
          A Offline
          Andrei Ungureanu
          wrote on last edited by
          #4

          i created a c++ dll in .net using a code like this: extern "C" { __declspec(dllexport) { //method body } __declspec(dllexport) { //method body } } try it. maybe it will work for you too! Do your best to be the best

          D 1 Reply Last reply
          0
          • A Andrei Ungureanu

            i created a c++ dll in .net using a code like this: extern "C" { __declspec(dllexport) { //method body } __declspec(dllexport) { //method body } } try it. maybe it will work for you too! Do your best to be the best

            D Offline
            D Offline
            dfbx
            wrote on last edited by
            #5

            thank you for your answer. but I cann't do it. because the DLL is already exist. it was from a video capturer SDK. the head file is defined as in the article. and all functions have been defined in a class. if i use [DlImport],compile is right, but when i run, an exception shown with"can not found the entrypoint from .dll". i think the trouble is the class defination. so i want to know how to use the class from the dll.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups