Developer Support Languages VC++, C# and VB.NET
Welcome to Microsoft Developer Support, Languages team blog! You will find a lot of language related troubleshooting resources here.
Troubleshooting PInvoke Related Issues
I am back with some more PInvoke Stuff. Recently I was working on a PInvoke issue which I found interesting.
I have a C++ dll which has a function whose signature is
int TestFunc(IN_STRUCT in_Params, RET_STRUCT * pret_Par).
I wanted to call this function from C#. Function has two arguments. First argument is input structure which will be filled from C# code and passed to C++ code. Second argument is output structure which is filled in C++ code and output to C# code.
Here are the C struct definitions and a function that needs to be marshaled
#include "stdafx.h"
#include <stdio.h>
#include "Objbase.h"
#include <malloc.h>
typedef struct IN_STRUCT
{
BYTE CMD_PType;
BYTE CMD_PTType;
BYTE CMD_OC;
BYTE CMD_Seq;
};
typedef struct RET_STRUCT
{
BYTE RET_OC;
BYTE RET_Seq;
BYTE RET_RetBytes;
char *str;
BYTE RET_PD[10];
};
extern "C" __declspec(dllexport) \
int TestFunc(IN_STRUCT in_Params, RET_STRUCT * pret_Par)
{
int iRet = 0;
pret_Par->RET_OC = in_Params.CMD_OC;
pret_Par-
Ïà¹ØÎĵµ£º
Ò»¡¢Access´ÓExcelÖе¼ÈëÊý¾Ý
1.Óõ½µÄExcel±íµÄ¸ñʽ¼°ÄÚÈÝ
ʵÏÖ
OleDbConnection con = new OleDbConnection();
try
{
OpenFileDialog openFile = new OpenFileDialog();//´ò¿ªÎļþ¶Ô»°¿ò¡£
openFile.Filter = ("Excel Îļþ(*.xls)|*.xls") ......
²úÆ·¼¸ÄêǰʹÓÃASP£¬ºóÀ´Éý¼¶µ½.Net 1.1£¬ÔÙÉý¼¶µ½2.0£¬Ò»Ö±¶¼ÓÐÓÃXSLTת»»XMLÉú³ÉÍøÒ³µÄ·½Ê½£¬ÉÔ΢ÕûÀíÏ¡£
XML file:
<?xml version="1.0" encoding="utf-8" ?>
<ric>
<catalog>
<book price ......
ίÍкÍʼþÔÚ .Net FrameworkÖеÄÓ¦Ó÷dz£¹ã·º£¬È»¶ø£¬½ÏºÃµØÀí½âίÍкÍʼþ¶ÔºÜ¶à½Ó´¥C#ʱ¼ä²»³¤µÄÈËÀ´Ëµ²¢²»ÈÝÒס£ËüÃǾÍÏñÊÇÒ»µÀ¼÷¶ù£¬¹ýÁËÕâ¸ö¼÷µÄÈË£¬¾õµÃÕæÊÇÌ«ÈÝÒ×ÁË£¬¶øûÓйýÈ¥µÄÈËÿ´Î¼ûµ½Î¯ÍкÍʼþ¾Í¾õµÃÐÄÀï±ð£¨bi裩µÃ»Å£¬»ìÉí²»×ÔÔÚ¡£±¾ÎÄÖУ¬ÎÒ½«Í¨¹ýÁ½¸ö·¶ÀýÓÉdzÈëÉîµØ½²ÊöʲôÊÇίÍС¢ÎªÊ²Ã´ÒªÊ¹Ó ......
c#±à³Ì»ù´¡Ö®¶þ£ºÌØÐÔ ÕâÀïµÄÌØÐÔÇø±ðÓÚÊôÐÔ£¬ËäÈ»msdnÖÐËƺõ²¢Ã»ÓÐÇø±ð¶þÕß¡£
ÊôÐÔ£ºÊÇÃæÏò¶ÔÏó±à³ÌµÄ»ù±¾¸ÅÄÌṩÁ˶Ô˽ÓÐ×ֶεķÃÎÊ·â×°£¬ÔÚC#ÖÐÒÔgetºÍset·ÃÎÊÆ÷·½·¨ÊµÏֶԿɶÁ¿ÉдÊôÐԵIJÙ×÷£¬ÌṩÁË°²È«ºÍÁé»îµÄÊý¾Ý·ÃÎÊ·â×°¡£
ÌØÐÔ£º¹«¹²ÓïÑÔÔËÐÐʱÔÊÐíÌí¼ÓÀàËƹؼü×ÖµÄÃèÊöÉùÃ÷£¬½Ð×öattributes, Ëü¶Ô³ÌÐòÖеÄÔ ......
c#ÊÂÎñ»Ø¹ö£¨×ª£©
×÷Õߣºxue5ya À´Ô´£º²©¿ÍÔ° ·¢²¼Ê±¼ä£º2009-03-20 16:08 ÔĶÁ£º263 ´Î ÔÎÄÁ´½Ó [ÊÕ²Ø]
Code
public void UpdateContactTableByDataSet(DataSet ds,string strTblName)
{
......