【发布时间】:2011-02-05 19:33:03
【问题描述】:
我试图在我的 c# 程序中使用一个 dll,但我似乎无法让它工作。我制作了一个如下所示的测试应用程序。返回值为 0,但它实际上并没有做它应该做的事情。
而以下命令确实有效:
rundll32 cmproxy.dll,SetProxy /source_filename proxy-1.txt /backup_filename roxy.bak /DialRasEntry NULL /TunnelRasEntry DSLVPN /Profile "C:\Documents and ettings\Administrator\Application Data\Microsoft\Network\Connections\Cm\dslvpn.cmp"
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.Net;
using WUApiLib;
namespace nac
{
class Program
{
[DllImport("cmproxy.dll", CharSet = CharSet.Unicode)]
static extern int SetProxy(string cmdLine);
static void Main(string[] args)
{
string cmdLine = @"/source_filename proxy-1.txt /backup_filename proxy.bak /DialRasEntry NULL /TunnelRasEntry DSLVPN /Profile ""C:\Documents and Settings\Administrator\Application Data\Microsoft\Network\Connections\Cm\dslvpn.cmp""";
Console.WriteLine(SetProxy(cmdLine));
}
}
}
这里是 dumpbin /exports 命令的内容
File Type: DLL
Section contains the following exports for cmproxy.dll
00000000 characteristics
3E7FEF8C time date stamp Tue Mar 25 05:56:28 2003
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 00001B68 SetProxy
Summary
1000 .data
1000 .reloc
1000 .rsrc
2000 .text
当它工作时,它会为 VPN 连接设置代理服务器。
编辑:
我希望避免从 system.process 运行 rundll32
我还可以提供指向 dll 和我的测试应用程序的链接。虽然上面粘贴的代码就是它所包含的全部内容,并且我认为可以从服务器资源工具包中获得 dll。
更新:
我用 C++ 编写了一个测试 DLL,它简单地回显了它给出的参数。它正在运行,但它说
句柄无效
【问题讨论】:
-
cmproxy.dll 的 .h 是什么样的?
-
我同意 Per,看看 SetProxy 的函数签名会很有帮助。
-
dll不是我写的,是微软提供的。有没有办法在没有源的情况下获取 .h 文件?
-
尝试使用 Visual Studio 中的对象浏览器打开 DLL。如果它有效,您将能够查看 DLL 公开的内容,然后查看函数签名。可能 SetProxy 函数签名与您在代码中定义它的方式不同。
-
表示无法浏览该dll。有趣的是它返回 0,所以人们会假设它有效并且命令行有问题。但是命令行使用rundll32工作,所以我想知道我是否没有正确形成命令行,或者它需要是不同的类型或其他东西