C#¶¯Ì¬µ÷ÓÃC++±àдµÄDLLº¯Êý
¶¯Ì¬¼ÓÔØDLLÐèҪʹÓÃWindows APIº¯Êý£ºLoadLibrary¡¢GetProcAddressÒÔ¼°FreeLibrary¡£ÎÒÃÇ¿ÉÒÔʹÓÃDllImportÔÚC#ÖÐʹÓÃÕâÈý¸öº¯Êý¡£
[DllImport("Kernel32")]
public static extern int GetProcAddress(int handle, String funcname);
[DllImport("Kernel32")]
public static extern int LoadLibrary(String funcname);
[DllImport("Kernel32")]
public static extern int FreeLibrary(int handle);
µ±ÎÒÃÇÔÚC++Öж¯Ì¬µ÷ÓÃDllÖеĺ¯Êýʱ£¬ÎÒÃÇÒ»°ãµÄ·½·¨ÊÇ£º
¼ÙÉèDLLÖÐÓÐÒ»¸öµ¼³öº¯Êý£¬º¯ÊýÔÐÍÈçÏ£º
BOOL __stdcall foo(Object &object, LPVOID lpReserved);
1¡¢Ê×Ïȶ¨ÒåÏàÓ¦µÄº¯ÊýÖ¸Õ룺
typedef BOOL (__stdcall *PFOO)(Object &object, LPVOID lpReserved);
2¡¢µ÷ÓÃLoadLibrary¼ÓÔØdll£º
HINSTANCE hInst = ::LoadLibraryW(dllFileName);
3¡¢µ÷ÓÃGetProcAddressº¯Êý»ñÈ¡Òªµ÷Óú¯ÊýµÄµØÖ·£º
PFOO foo = (PFOO)GetProcAddress(hInst,"foo");
if(foo == NULL)
{
FreeLibrary(hInst);
return false;
}
4¡¢µ÷ÓÃfooº¯Êý£º
BOOL bRet = foo(object,(LPVOID)NULL);
5¡¢Ê¹ÓÃÍêºóÓ¦ÊÍ·ÅDLL£º
FreeLibrary(hInst);
ÄÇôÔÚC#ÖÐÓ¦¸ÃÔõô×öÄØ£¿·½·¨»ù±¾ÉÏÒ»Ñù£¬ÎÒÃÇʹÓÃίÍÐÀ´´úÌæC++µÄº¯ÊýÖ¸Õ룬ͨ¹ý.NET Framework 2.0ÐÂÔöµÄº¯ÊýGetDelegateForFunctionPointerÀ´µÃµ½Ò»¸öίÍеÄʵÀý£º
ÏÂÃæ·â×°ÁËÒ»¸öÀ࣬ͨ¹ý¸ÃÀàÎÒÃǾͿÉÒÔÔÚC#Öж¯Ì¬µ÷ÓÃDllÖеĺ¯ÊýÁË£º
public class DLLWrapper
{
///<summary>
/// API LoadLibrary
///</summary>
[DllImport("Kernel32")]
public static extern int LoadLibrary(String funcname);
///<summary>
/// API GetProcAddress
///</summary>
[DllImport("Kernel32")]
public static extern int GetProcAddress(int handle, String funcname);
///<summary>
/// API FreeLibrary
///</summary>
&
Ïà¹ØÎĵµ£º
public string WriteXML(string[] values, int flag)
{
//Èç¹ûflag==0ÔòΪµÚÒ»´ÎÔËÐÐÐèÒª³õʼ»¯XMLÎļþ
if (flag == 0)
{
//ÉúÔÚËæ»úÎļþÃû
string dateName = System.DateTime.Now.ToString("yyyyMMddHHmmss");
......
·½·¨Ò»£º±éÀúÕýÔÚÓÐÏàͬÃû×ÖÔËÐеÄÀý³Ì
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace DHPSS.COM
{
/// <summary>
/// c#³ÌÐòÖ»ÔËÐÐÒ»´Î£¬C#Àý³ÌÖ»ÔËÐÐÒ»´Î
/// http://blog.csdn.net/nnsw ......
c#±à³Ì»ù´¡Ö®¶þ£ºÌØÐÔ ÕâÀïµÄÌØÐÔÇø±ðÓÚÊôÐÔ£¬ËäÈ»msdnÖÐËƺõ²¢Ã»ÓÐÇø±ð¶þÕß¡£
ÊôÐÔ£ºÊÇÃæÏò¶ÔÏó±à³ÌµÄ»ù±¾¸ÅÄÌṩÁ˶Ô˽ÓÐ×ֶεķÃÎÊ·â×°£¬ÔÚC#ÖÐÒÔgetºÍset·ÃÎÊÆ÷·½·¨ÊµÏֶԿɶÁ¿ÉдÊôÐԵIJÙ×÷£¬ÌṩÁË°²È«ºÍÁé»îµÄÊý¾Ý·ÃÎÊ·â×°¡£
ÌØÐÔ£º¹«¹²ÓïÑÔÔËÐÐʱÔÊÐíÌí¼ÓÀàËƹؼü×ÖµÄÃèÊöÉùÃ÷£¬½Ð×öattributes, Ëü¶Ô³ÌÐòÖеÄÔ ......
c#ÊÂÎñ»Ø¹ö£¨×ª£©
×÷Õߣºxue5ya À´Ô´£º²©¿ÍÔ° ·¢²¼Ê±¼ä£º2009-03-20 16:08 ÔĶÁ£º263 ´Î ÔÎÄÁ´½Ó [ÊÕ²Ø]
Code
public void UpdateContactTableByDataSet(DataSet ds,string strTblName)
{
......
·þÎñÆ÷¶Ë´úÂë
¿Ø¼þ£ºbtnStart_Click£¬btnSend_Click£¬label4£¬textBox1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
using S ......