Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# convert structures
Hello guys, I need to use a C++ Dll at C#, so I figure that I need to re-write some structs and enums. I have this code at my header file in C++.
 
#pragma mark STRUCTURES
 
    typedef void* QCam_Handle;
 
    typedef struct _TAG_CAM_SETTINGS_ID_GUID_STRUCT_
    {
 

        uint32_t f1;
        uint16_t f2;
        uint16_t f3;
        uint8_t  f4[8];
    }QCam_settings_id, *pQCam_settings_id;
 
    // QCam_Settings is obsolete. Use QCam_SettingsEx in conjunction with QCam_CreateCameraSettingsStruct,
    // QCam_Err QCam_InitializeCameraSettings and QCam_ReleaseCameraSettings
    typedef struct
    {
        unsigned long size;
        unsigned long _private_data[ 64 ];
    }
    QCam_Settings;
 
    typedef struct
    {
        unsigned long       size;                   // Filled by the initialization routine
        QCam_settings_id    _pSettingsID;           // pointer to the camera settings ID
        unsigned long       *_private_data;         // Pointer to a camera settings array
    }
    QCam_SettingsEx, *pQCam_SettingsEx;
 
    typedef struct
    {
        unsigned long       cameraId;           // Camera ID (ex: 0 for first camera, 1 for second)
        unsigned long       cameraType;         // Camera Model
        unsigned long       uniqueId;           // Unique ID for the camera
        unsigned long       isOpen;             // 1 if already open, 0 if closed

        unsigned long       _reserved[ 10 ];
    }
    QCam_CamListItem;
 
Is there any way to do that? I'm starting at this, some help would be wonderful
Posted 18-Mar-13 1:45am
Comments
CHill60 at 18-Mar-13 7:26am
   
It's not clear what you are trying to do ... are you trying to rewrite the C++ code in C# or are you trying to call a C++ dll from C#
GustavoUgioni at 18-Mar-13 8:14am
   
I'm trying to call a C++ dll from C#, but that dll has some methods that the return type are from typedef enum, such as:
 

* QCam_ListCameras()
*
* Discussion:
* Retrieve a list of connected cameras.
*
* Parameters:
* (IN) pList - User allocated array to fill in
* (OUT) pList - Filled in with the list of connected cameras
* (IN) pNumberInList - Length of the array
* (OUT) pNumberInList - Number of cameras found
*
* Remarks:
* On return, pNumberInList may contain a number that is bigger than the array size.
*
* Result:
* QCam_Err code
*/
extern QCam_Err QCAMAPI QCam_ListCameras
(
QCam_CamListItem* pList,
unsigned long* pNumberInList
);
 
Where QCam_Err is:
 
typedef enum
{
qerrSuccess = 0,
qerrNotSupported = 1,
...
qerrStreamFault = 30, // Stream allocation failed, there may not be enough bandwidth
qerrQCamUpdateNeeded = 31, // QCam needs to be updated
qerrRoiTooSmall = 32, // The ROI used is too small
qerr_last = 33,
_qerr_force32 = 0xFFFFFFFF
}
QCam_Err;
 
And there are also some methods that the return type are structs.
 
I thought I should rewrite some parts of the header file in C#, or is that a cleaver way to do that?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 300
1 Mathew Soji 274
2 Afzaal Ahmad Zeeshan 268
3 DamithSL 225
4 Sergey Alexandrovich Kryukov 205
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 18 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100