主要代码如下: [DllImport("MwNetGate.dll")]
public static extern int ConnectOpen(
string Uid,
string Password,
string ServerIP,
int ServerPort
); private void button1_Click(object sender, System.EventArgs e)
{
if (ConnectOpen("xxxxxxxxxxxx", "xxxxxxx", "61.242.89.115", 8018) == 0)
{
MessageBox.Show("ConnectOK");
}
else
{
MessageBox.Show("ConnectERR");
}
}编译通过, button1_Click时报错如下:
其他信息: 无法在 DLL MwNetGate.dll 中找到名为 ConnectOpen 的入口点。此DLL我在ASP下运行正常!!!!
public static extern int ConnectOpen(
string Uid,
string Password,
string ServerIP,
int ServerPort
); private void button1_Click(object sender, System.EventArgs e)
{
if (ConnectOpen("xxxxxxxxxxxx", "xxxxxxx", "61.242.89.115", 8018) == 0)
{
MessageBox.Show("ConnectOK");
}
else
{
MessageBox.Show("ConnectERR");
}
}编译通过, button1_Click时报错如下:
其他信息: 无法在 DLL MwNetGate.dll 中找到名为 ConnectOpen 的入口点。此DLL我在ASP下运行正常!!!!
解决方案 »
- 如何从textbox.text转换成datetime.now.tolong.tostring()
- 把winform做为windows服务然后在asp.net中调用服务程序。
- xml的读取问题
- 求答案 .exe 怎么在别人机子上运行!!!!!!!!!!??????????????
- 求助:线程间操作无效
- 请问那你有.Net 水晶报表的案例教程。
- 仿QQ界面,自定义UserControl之后的Font和Text属性的问题,设计器不能自动加入代码
- 怎么能得到checkedListBox选中了哪些数据
- cs的函数签名问题,急啊!高手帮忙
- 求大佬出手C# winform datagridview
- c#每日一题(五),高手莫入!
- mdi主窗口背景图片问题
在C#里只需要调用PInvoke (Platform Invocation) 服务。C# 支持一种sysimport属性
支持这种调用。
下面是完整的语法形式(在例子里没有用到所有的参数):[sysimport(
dll=dllName,
name=functionName,
charset=characterSetToBeUsed)
]给出一个调用Win32 MessageBox函数的例子:using System;class pinvokeClient
{
[sysimport(dll="user32.dll")]public static extern int MessageBoxA(int hwnd, string message,
string caption, int type);public static void Main()
{
int result = MessageBoxA(0, "Hello World", "PInvoke Test", 0);
}
}
public class Win32
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int MessageBox(
int hWnd,
String text,
String caption,
uint type);
}
private void button2_Click(object sender, EventArgs e)
{
Win32.MessageBox(0, "Hello World", "Platform Invoke Sample", 0);
}我试过这样是OK的,但是我的那个DLL就会报错说找不到入口点,DELPHI编译的DLL和user32.dll有什么区别没有?
要设置一下编译器的选项,把调用dll方式从C语言方式改为标准方式VS与Delphi编译dll不一样的
----------------------------------------------------
连什么是dll都搞不清楚. vcl与dll有什么关系吗?
只要是在windows平台下,dll 格式是相同的. 不一定要编译成com形式也可以调用.应该是你声明的参数或其类型与dll里的不符合 (如果你在asp下运行正确的话)
要么就没有这个入口函数.
用VB。NET调用如下调用
Dim monGate As Object
monGate = CreateObject("MwNetGate.OneWayInterface")
.
.
.
程序就可以编译使用了,不知道为什么会这样
当调用用户定义的 DLL 中所包含的函数时,有必要将 extern "C" 添加在 DLL 函数声明之前,如下所示:
The function declaration in SampleDLL.h file
extern "C" SAMPLEDLL_API int fnSampleDLL(void);详见http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vccore/html/vcwlksysimportattributetutorial.asp但愿有用!
可以用dependency walker看看。