紧急求助:vb.net如何调用C#写的类DLL

dy_yong 2007-07-17 12:02:52
我用c#写了一个类,并生了类库dll,我在vb.net调用,我调用dll中的get方法都没有提示错误,而调用另外一个方法,就直接异常了,请高手指点,将另外赠分!
...全文
368 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
兔子-顾问 2007-07-18
  • 打赏
  • 举报
回复
建议你还是别这样作了。这个做法在win98时候啊还推荐,win2k开始,这个方法就只在wince,ppc,mobile上使用。.net下你可以用.net方法来遍历进程
For Each p As Process In Process.GetProcesses
'
Next
Avoid 2007-07-18
  • 打赏
  • 举报
回复
toolhelp.dll这个dll在不在?

没有的话就会出错
MicroSoftor 2007-07-17
  • 打赏
  • 举报
回复
既然可以调用,那说明加载什么的已经正常工作了
可能是方法问题,或是需要的条件不全
xxelement 2007-07-17
  • 打赏
  • 举报
回复
什么异常?
feiyun0112 2007-07-17
  • 打赏
  • 举报
回复
具体代码,c#和vb的

*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)

http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
dy_yong 2007-07-17
  • 打赏
  • 举报
回复
C#方法:
public static Process[] GetProcesses()
{
ArrayList procList = new ArrayList();

IntPtr handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if ((int)handle > 0)
{
try
{
PROCESSENTRY32 peCurrent;
PROCESSENTRY32 pe32 = new PROCESSENTRY32();
//Get byte array to pass to the API calls
byte[] peBytes = pe32.ToByteArray();
//Get the first process
int retval = Process32First(handle, peBytes);

while(retval == 1)
{
//Convert bytes to the class
peCurrent = new PROCESSENTRY32(peBytes);
//New instance
Process proc = new Process(new IntPtr((int)peCurrent.PID), peCurrent.Name, (int)peCurrent.ThreadCount, (int)peCurrent.BaseAddress);

procList.Add(proc);

retval = Process32Next(handle, peBytes);
}
}
catch(Exception ex)
{
throw new Exception("Exception: " + ex.Message);
}

//Close handle
CloseToolhelp32Snapshot(handle);

return (Process[])procList.ToArray(typeof(Process));

}
else
{
throw new Exception("Unable to create snapshot");
}


}
dy_yong 2007-07-17
  • 打赏
  • 举报
回复
我的c#的类中定义了
private const int TH32CS_SNAPPROCESS = 0x00000002;
[DllImport("toolhelp.dll")]
public static extern IntPtr CreateToolhelp32Snapshot(uint flags, uint processid);
我要调用的方法中存在这个
IntPtr handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
我在vb.net中跟踪到C#方法的这个地方就异常了
未处理的“System.MissingMethodException”类型的异常

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧