C# 参数在进入函数体后更改 我在C++项目中创建了两个函数,一个是OrnIAL函数: CLIB_ENUM CLIB_CreateDeviceLinkFile( CLIB_C_WCHAR* pSrcProfile, CLIB_C_WCHAR* pDstProfile, CLIB_C_WCHAR* pDvlProfile, CLIB_ENUM rend_intent ) { CLIB_ErrorCode rc = CLIB_SUCCESSFUL; CLIB_Intent intent = static_cast<CLIB_Intent>( rend_intent ); // Verify that the input parameters. if( pSrcProfile == 0 || wcslen( pSrcProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid source profile path" ); rc = CLIB_INVALID_PARAMETER; } else if( pDstProfile == 0 || wcslen( pDstProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid destination profile path" ); rc = CLIB_INVALID_PARAMETER; } else if( pDvlProfile == 0 || wcslen( pDvlProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid device-link path" ); rc = CLIB_INVALID_PARAMETER; } else if( intent != CLIB_PERCEPTUAL && intent != CLIB_RELATIVE_COLORIMETRIC && intent != CLIB_SATURATION && intent != CLIB_ABSOLUTE_COLORIMETRIC ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid rendering intent" ); rc = CLIB_INVALID_PARAMETER; } if( rc == CLIB_SUCCESSFUL ) { try { // Create file specs for the profiles. GFIL_FileSpec srcProfileSpec( GFIL_SpecFromPlatformPath( GLIB_WString( pSrcProfile ) ) ); GFIL_FileSpec dstProfileSpec( GFIL_SpecFromPlatformPath( GLIB_WString( pDstProfile ) ) ); GFIL_FileSpec dvlProfileSpec( GFIL_SpecFromPlatformPath( GLIB_WString( pDvlProfile ) ) ); // Create the device link file rc = CLIB_CreateDeviceLinkFilePriv( srcProfileSpec, dstProfileSpec, dvlProfileSpec, iCLIB_ConvertIntent( intent ) ); } catch( const GLIB_Exception& ex ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - error creating device link file: " << ex ); rc = CLIB_UKNOWN_ERROR; } } return static_cast<CLIB_ENUM>( rc );} CLIB_ENUM CLIB_CreateDeviceLinkFileCEV2( CLIB_C_WCHAR* pSrcProfile, CLIB_C_WCHAR* pDstProfile, CLIB_C_WCHAR* pDvlProfile, CLIB_ENUM rend_intent ){ CLIB_ErrorCode rc = CLIB_SUCCESSFUL; CLIB_Intent intent = static_cast<CLIB_Intent>( rend_intent ); // Verify that the input parameters. if( pSrcProfile == 0 || wcslen( pSrcProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid source profile path" ); rc = CLIB_INVALID_PARAMETER; } else if( pDstProfile == 0 || wcslen( pDstProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid destination profile path" ); rc = CLIB_INVALID_PARAMETER; } else if( pDvlProfile == 0 || wcslen( pDvlProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid device-link path" ); rc = CLIB_INVALID_PARAMETER; } else if( intent != CLIB_PERCEPTUAL && intent != CLIB_RELATIVE_COLORIMETRIC && intent != CLIB_SATURATION && intent != CLIB_ABSOLUTE_COLORIMETRIC ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid rendering intent" ); rc = CLIB_INVALID_PARAMETER; } if( rc == CLIB_SUCCESSFUL ){ ProfileUtil util; bool bDoBPC =false; int rendIntent = 0; int iLinkTypeReq = 0; // init to dynamic int iLinkTypeReturned = 0; int iLinkTypeExpected = 1; StringUtils strUtil; string strSrcProfile=strUtil.WcharToChar(pSrcProfile); string strDstProfile=strUtil.WcharToChar(pDstProfile); string strDvlProfile=strUtil.WcharToChar(pDvlProfile); CEError error=util.CreateDVL( true, bDoBPC, rend_intent, iLinkTypeReq, iLinkTypeReturned, strSrcProfile, strDstProfile, strDvlProfile ); switch(error){ case CEErr_none:{ rc = CLIB_SUCCESSFUL; };break; case CEErr_badParam:{ rc=CLIB_INVALID_PARAMETER; };break; case CEErr_ICC_InvalidTagType:{ rc=CLIB_TAG_UNDEFINED; };break; case CEErr_ICC_TagNotFound:{ rc=CLIB_TAG_UNDEFINED; };break; case CEErr_unknown:{ rc=CLIB_UKNOWN_ERROR; };break; default:{ rc=CLIB_UKNOWN_ERROR; } } } return static_cast<CLIB_ENUM>( rc ); }

C# 参数在进入函数体后更改 我在C++项目中创建了两个函数,一个是OrnIAL函数: CLIB_ENUM CLIB_CreateDeviceLinkFile( CLIB_C_WCHAR* pSrcProfile, CLIB_C_WCHAR* pDstProfile, CLIB_C_WCHAR* pDvlProfile, CLIB_ENUM rend_intent ) { CLIB_ErrorCode rc = CLIB_SUCCESSFUL; CLIB_Intent intent = static_cast<CLIB_Intent>( rend_intent ); // Verify that the input parameters. if( pSrcProfile == 0 || wcslen( pSrcProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid source profile path" ); rc = CLIB_INVALID_PARAMETER; } else if( pDstProfile == 0 || wcslen( pDstProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid destination profile path" ); rc = CLIB_INVALID_PARAMETER; } else if( pDvlProfile == 0 || wcslen( pDvlProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid device-link path" ); rc = CLIB_INVALID_PARAMETER; } else if( intent != CLIB_PERCEPTUAL && intent != CLIB_RELATIVE_COLORIMETRIC && intent != CLIB_SATURATION && intent != CLIB_ABSOLUTE_COLORIMETRIC ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid rendering intent" ); rc = CLIB_INVALID_PARAMETER; } if( rc == CLIB_SUCCESSFUL ) { try { // Create file specs for the profiles. GFIL_FileSpec srcProfileSpec( GFIL_SpecFromPlatformPath( GLIB_WString( pSrcProfile ) ) ); GFIL_FileSpec dstProfileSpec( GFIL_SpecFromPlatformPath( GLIB_WString( pDstProfile ) ) ); GFIL_FileSpec dvlProfileSpec( GFIL_SpecFromPlatformPath( GLIB_WString( pDvlProfile ) ) ); // Create the device link file rc = CLIB_CreateDeviceLinkFilePriv( srcProfileSpec, dstProfileSpec, dvlProfileSpec, iCLIB_ConvertIntent( intent ) ); } catch( const GLIB_Exception& ex ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - error creating device link file: " << ex ); rc = CLIB_UKNOWN_ERROR; } } return static_cast<CLIB_ENUM>( rc );} CLIB_ENUM CLIB_CreateDeviceLinkFileCEV2( CLIB_C_WCHAR* pSrcProfile, CLIB_C_WCHAR* pDstProfile, CLIB_C_WCHAR* pDvlProfile, CLIB_ENUM rend_intent ){ CLIB_ErrorCode rc = CLIB_SUCCESSFUL; CLIB_Intent intent = static_cast<CLIB_Intent>( rend_intent ); // Verify that the input parameters. if( pSrcProfile == 0 || wcslen( pSrcProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid source profile path" ); rc = CLIB_INVALID_PARAMETER; } else if( pDstProfile == 0 || wcslen( pDstProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid destination profile path" ); rc = CLIB_INVALID_PARAMETER; } else if( pDvlProfile == 0 || wcslen( pDvlProfile ) == 0 ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid device-link path" ); rc = CLIB_INVALID_PARAMETER; } else if( intent != CLIB_PERCEPTUAL && intent != CLIB_RELATIVE_COLORIMETRIC && intent != CLIB_SATURATION && intent != CLIB_ABSOLUTE_COLORIMETRIC ) { GLIB_NLOG_ERROR( "CLIB_CreateDeviceLinkFile - invalid rendering intent" ); rc = CLIB_INVALID_PARAMETER; } if( rc == CLIB_SUCCESSFUL ){ ProfileUtil util; bool bDoBPC =false; int rendIntent = 0; int iLinkTypeReq = 0; // init to dynamic int iLinkTypeReturned = 0; int iLinkTypeExpected = 1; StringUtils strUtil; string strSrcProfile=strUtil.WcharToChar(pSrcProfile); string strDstProfile=strUtil.WcharToChar(pDstProfile); string strDvlProfile=strUtil.WcharToChar(pDvlProfile); CEError error=util.CreateDVL( true, bDoBPC, rend_intent, iLinkTypeReq, iLinkTypeReturned, strSrcProfile, strDstProfile, strDvlProfile ); switch(error){ case CEErr_none:{ rc = CLIB_SUCCESSFUL; };break; case CEErr_badParam:{ rc=CLIB_INVALID_PARAMETER; };break; case CEErr_ICC_InvalidTagType:{ rc=CLIB_TAG_UNDEFINED; };break; case CEErr_ICC_TagNotFound:{ rc=CLIB_TAG_UNDEFINED; };break; case CEErr_unknown:{ rc=CLIB_UKNOWN_ERROR; };break; default:{ rc=CLIB_UKNOWN_ERROR; } } } return static_cast<CLIB_ENUM>( rc ); },c#,c++,pinvoke,C#,C++,Pinvoke,有什么问题吗?我们看不到所有的类型声明,所以我们只能相信您的翻译是正确的。除此之外,C代码唯一的错误就是调用约定不匹配。非托管代码是\uu cdecl,但托管代码使用\uu stdcall。托管代码应为: [DllImport("...", CallingConvenction = CallingConvenction.Cdecl, CharSet = CharSet.Unicode)] 还要注意,您使用的SetLastError不正确,因此我已将其删除 如果发现代码中没有显示的其他

有什么问题吗?

我们看不到所有的类型声明,所以我们只能相信您的翻译是正确的。除此之外,C代码唯一的错误就是调用约定不匹配。非托管代码是
\uu cdecl
,但托管代码使用
\uu stdcall
。托管代码应为:

[DllImport("...", CallingConvenction = CallingConvenction.Cdecl, 
    CharSet = CharSet.Unicode)]
还要注意,您使用的
SetLastError
不正确,因此我已将其删除


如果发现代码中没有显示的其他内容意味着调用约定匹配,那么本课程将显示一个。如果发现代码中存在我们看不到的问题,那么课程就是显示。

show a以消除对代码内容的怀疑即使两个函数的参数相同,您似乎认为这就是问题所在。那没有任何意义。显然,这与函数的内容有关,出于某种奇怪的原因,你决定不包含它。@JonathanWood我已经更新了代码,我的观点是,参数的值在进入函数体之前是正确的,但在刚进入函数体时变为无意义的值,但帖子中的代码都是一样的,我刚刚更改了底线的实现,在执行我更改的代码之前发生了异常。
[DllImport("...", CallingConvenction = CallingConvenction.Cdecl, 
    CharSet = CharSet.Unicode)]