Calling unmanaged code from within C#
Posted
by Charles Gargent
on Stack Overflow
See other posts from Stack Overflow
or by Charles Gargent
Published on 2010-04-08T17:12:26Z
Indexed on
2010/04/08
19:43 UTC
Read the original article
Hit count: 349
I am trying to use a dll in my c# program but I just cant seem to get it to work. I have made a test app shown below. The return value is 0, however it does not actually do what it is supposed to do.
Whereas the following command does work:
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"
Code:
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));
}
}
}
Here is the contents of the dumpbin /exports command
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
When this works it sets the proxy server for a VPN connection.
© Stack Overflow or respective owner