本文介绍了指定演员表无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 尝试从测试dll中调用Find()即时消息并且我一直收到错误指定的演员表无效。 这里有一个小片段我正在使用..... test.dll foo.h __ declspec ( dllexport )UINT Find(); foo.cpp UINT Find() { return 1 ; } C#test.exe使用界面进行通话 [ComImport,CoClass( typeof ( object )),TypeIdentifier,CompilerGenerated,Guid( MYGUID)] public interface CSmart:ISmart {} [ComImport,TypeIdentifier,CompilerGenerated,Guid( MYGUID)] public interface ISmart { [DispId( 1 )] uint Find(); } 这里是按钮推送 private CSmart来电; 此 .caller =(CSmart)Activator.CreateInstance(Type.GetTypeFromCLSID( new Guid( MYGUID))); 尝试 { caller.Find(); // < ---这里是错误弹出 } catch (Exception ex) { // 指定演员表无效。 } 将dll加载到依赖步行者节目中 1 (0x0001)| 0 (0x0000)| unsigned int 查找( void )| 0x00011091 我尝试过: 不知道从哪里开始.... lol 解决方案 导出的函数对我来说看起来不像COM对象。我不是C#的优秀专家,但如果你所拥有的只是一个C函数,你不能在导入后直接调用它: class urgle { [DllImport( test.dll)] public static extern UINT Find(); }; 就是你需要的东西。 trying to call Find() from a test dll im messing with and I keep getting the error"Specified cast is not valid."here's a little snippet of what im working with.....test.dllfoo.h__declspec(dllexport) UINT Find();foo.cppUINT Find(){return 1;}C# test.exe using interface for the call[ComImport, CoClass(typeof(object)), TypeIdentifier, CompilerGenerated, Guid("MYGUID")] public interface CSmart : ISmart { } [ComImport, TypeIdentifier, CompilerGenerated, Guid("MYGUID")] public interface ISmart { [DispId(1)] uint Find();}here is the button pushprivate CSmart caller;this.caller = (CSmart)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("MYGUID"))); try { caller.Find(); //<---here is when the error pops }catch (Exception ex) { //Specified cast is not valid. }Loading the dll into dependancy walker shows1(0x0001) | 0(0x0000) | unsigned int Find(void) | 0x00011091What I have tried:not sure where to start....lol 解决方案 Your exported function doesn't look like a COM object to me. I'm not a great expert on C# but if all you've got is a C function can't you just call it directly after importing it:class urgle{ [DllImport("test.dll")] public static extern UINT Find();};is the sort of thing you need. 这篇关于指定演员表无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 17:26