开发者

C# - Calling unmanaged function with a fixed size out parameter

开发者 https://www.devze.com 2023-04-13 00:00 出处:网络
I\'ve been searching for the last 12 hours or so and don\'t think I\'m even on the right track at this point or if I\'m wording my searches properly. I\'m hoping someone can point me in the right dire

I've been searching for the last 12 hours or so and don't think I'm even on the right track at this point or if I'm wording my searches properly. I'm hoping someone can point me in the right direction here.

I'm attempting to access a function in an unmanaged library that takes as one of it's parameters a fixed size DWORD array and I'm not sure how to specify this in the declaration or call. I'm also not sure开发者_JAVA技巧 if the documentation for the function is correct (or if I understand it).

int EloGetScreenInfo(DWORD dwMonNum[32], int iScrCnt)

Parameters: dwMonNum [in]: Array of DWORD to receive the Windows monitor number associated with the touchscreens.

iScrCnt [out]: It retrieves the total number of Elo touchscreens found.

Return Values: Returns EloSuccess if the call succeeds, it returns an error code otherwise. See Error Codes section for list of error values.

Remarks:

It returns the list of Windows monitor numbers associated with the touchscreens where, the index is the touchscreen number and the value is the Windows monitor number.

Touchscreens are 0 based and Windows monitor numbers are 1 based.

If a touchscreen is not calibrated, the windows monitor is returned as -1.

Maximum of 32 touchscreens are supported.

Notice in the description it states that it returns a list of monitor numbers which would suggest that it would be the populated value, yet in the parameter descriptions it shows that as an [in] and the count parameter as an [out] unless i'm misinterpreting the descriptions. In a See Also Sample link it shows an example of usage in which both seem to be populated

    DWORD dwEnumMon[MAX_SUPPORTED_SCR] ;
    int iScrCnt, iRet ;

    ZeroMemory( dwEnumMon, MAX_SUPPORTED_SCR ) ;
    ZeroMemory( dwMonParam, MAX_SUPPORTED_SCR ) ;

    // Get the list of all Elo Serial & USB screen and monitor association
    iRet = EloGetScreenInfo(dwEnumMon,iScrCnt) ;
    if(iRet != EloSuccess ){
        printf( "Error Code = %d \n", iRet ) ;
        return EloFailure;
    }
    else
    if(iScrCnt<0){
        printf( "No Elo touchscreens found\n" ) ;
        return EloFailure;
    }

    // Process Commandline
    ProcessCmdLine( argc, argv ) ;

    // For all screens of matching monitor number enable / disable touch
    for( int i=0; i<dwMonParamCnt; i++ ){
        // where j is the screen number associated with the monitor number
        for( int j=0; j<iScrCnt; j++ ){
            if( dwMonParam[i] == dwEnumMon[j] ){
                // Enables / Disables touch depending on the bFlag
                // where j is the screen number
                if( (iRet = EloSetTouchReportingState( bEnable , j )) == EloSuccess )
                    printf( "EloSetTouchReportingState Returned success\n" );
                else
                    printf( "EloSetTouchReportingState Returned failed. Error \ Code=%d\n", iRet );
               }
           }
      }

      return EloSuccess;

TIA for any direction or help you can provide


You should be able to call this with a normal array of UInt32. Your managed prototype would be:

[DLLImport "DllName"]
static extern int EloGetScreenInfo(UInt32[] dwMonNum, out int iScrCnt);

And to call it, just specify the marshaling:

UInt32[] MonitorNumbers = new UInt32[32];
int iScrCnt = 0;

int rslt = EloGetScreenInfo(
    [MarshalAs(UnmanagedType.LPArray, SizeConst=32)] MonitorNumbers,
    out iScrCnt);


This is what MSDN suggests:

using DWORD = System.UInt32;

int YourUnmanagedFunction([MarshalAs(UnmanagedType.LPArray, SizeConst=32)] DWORD[] array);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号