C语言的代码  
typedef struct
{
DJ_S8 m_s8ServerIp[32]; /*XMS server ip*/
DJ_U32 m_u32ServerPort; /*XMS server port*/
DJ_S8 m_s8UserName[32]; /**/
DJ_S8 m_s8UserPwd[32]; /**/
}ServerID_t;/**/
/**/
ServerID_t cfg_ServerID;
/*调用acsOpenStream 建立与ACS服务器的连接*/
r = XMS_acsOpenStream ( &g_acsHandle, 
&cfg_ServerID,
g_u8UnitID, // App Unit ID 
32, // sendQSize, in K Bytes
32, // recvQSize, in K Bytes
cfg_s32DebugOn, // Debug On/Off
NULL);
人家把C代码转成ActiveX控件
在NET中AcsOpenStream(ref int acsHandle, ref int serverID, short u8AppID, int u32SendQSize, int u32RecvQSize, int s32DebugOn, ref int privateData);ref int serverIDserverID应该对应的是ServerID_t类型,那为怎么会变成 (ref int serverID)    INT哪?怎么解决啊。

解决方案 »

  1.   

    有人会知道 C#的struct 的指针用法嘛?
      

  2.   

    如果你说的struct的指针using System;
    using System.Runtime.InteropServices;public struct Point
    {
        public int x;
        public int y;
    }class Example
    {    static void Main()
        {        // Create a point struct.
            Point p;
            p.x = 1;
            p.y = 1;        Console.WriteLine("The value of first point is " + p.x + " and " + p.y + ".");        // Initialize unmanged memory to hold the struct.
            IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(p));        try
            {            // Copy the struct to unmanaged memory.
                Marshal.StructureToPtr(p, pnt, false);            // Create another point.
                Point anotherP;            // Set this Point to the value of the 
                // Point in unmanaged memory. 
                anotherP = (Point)Marshal.PtrToStructure(pnt, typeof(Point));            Console.WriteLine("The value of new point is " + anotherP.x + " and " + anotherP.y + ".");        }
            finally
            {
                // Free the unmanaged memory.
                Marshal.FreeHGlobal(pnt);
            }    }}
      

  3.   

    http://msdn2.microsoft.com/zh-cn/library/2k1k68kw.aspx
    http://msdn2.microsoft.com/zh-cn/library/eadtsekz.aspx
    http://msdn2.microsoft.com/zh-cn/library/3k3z0k7a.aspx
    http://msdn2.microsoft.com/zh-cn/library/xedhyxyd.aspx
      

  4.   

    看看这个也许有帮助!
    http://www.programfan.com/club/showpost.asp?id=16320
      

  5.   

    为怎么会出现这个错误
    错误 1 不安全代码只会在使用 /unsafe 编译的情况下出现
    我们公司只能访问 CSDN外网不开放。 
      

  6.   

    右键工程-属性-bulid-allow unsafe code
      

  7.   


    unsafe
    {
    }
    把不安全代码包含在内部。
      

  8.   

    按照你的C语言的代码:
      
    typedef struct 

    DJ_S8 m_s8ServerIp[32]; /*XMS server ip*/ 
    DJ_U32 m_u32ServerPort; /*XMS server port*/ 
    DJ_S8 m_s8UserName[32]; /**/ 
    DJ_S8 m_s8UserPwd[32]; /**/ 
    }ServerID_t;/**/ 
    /**/ 
    ServerID_t cfg_ServerID; 推测DJ_S8是char类型,DJ_U32是unsigned int类型,在c#中定义:Struct XMLServerInfo

        byte[32] ServerIp[32]; 
        uint     ServerPort; 
        byte[32] UserName[32];
        byte[32] UserPwd[32]; 
    }
    XMLServerInfo myServerInfo = new XMLServerInfo();unsafe 
    {
        AcsOpenStream(x,&myServerInfo...); 
    } 通过
    string buffer;
    buffer = System.Text.Encoding.Default.GetString(myServerInfo.ServerIp); 
    获得字符串信息。
      

  9.   

    大家可以到我的下载的URL中下载下ActiveX 。 
    http://download.csdn.net/user/lhsxsh
     名称为“ActiveX控件在NET中的使用”
    大家帮我测试下 
    AcsOpenStream(ref int acsHandle, ref int serverID, short u8AppID, int u32SendQSize, int u32RecvQSize, int s32DebugOn, ref int privateData); 
    方法中的 ref int serverID() 参数为ServerID_t的结构体C语言的代码   
    typedef struct 

    DJ_S8 m_s8ServerIp[32]; /*XMS server ip*/ 
    DJ_U32 m_u32ServerPort; /*XMS server port*/ 
    DJ_S8 m_s8UserName[32]; /**/ 
    DJ_S8 m_s8UserPwd[32]; /**/ 
    }ServerID_t;/**/ 
    /**/ 
    ServerID_t cfg_ServerID;  
      

  10.   

    C的定义如下:
    typedef unsigned char     DJ_U8;
    typedef char              DJ_S8;
    typedef unsigned short    DJ_U16;
    typedef short             DJ_S16; 
    typedef unsigned int   DJ_U32;
    typedef int   DJ_S32; 
    typedef unsigned long     DJ_U32;
    typedef long              DJ_S32;
    typedef unsigned long DJ_U40;
    typedef long DJ_S40;
    typedef double  DJ_U64;
    typedef double          DJ_S64;
    typedef unsigned long long DJ_U64;
    typedef long long         DJ_S64;
    typedef bool              BOOL; 
    对应到c#时我们要何类型,有些不是很确认如:long long          在NET是我们要怎么定义? 
    short 是不是对应NET的int16?
      

  11.   

    Struct XMLServerInfo 
    {  
        byte[32] ServerIp[32];  
        uint     ServerPort;  
        byte[32] UserName[32]; 
        byte[32] UserPwd[32];  

    这样的定义在C#中好像语法不对吧。
      

  12.   

    不好意思,呵呵,各种语言搞混了,又写错。复制一个我在工程里用的修改一下:
    private struct ReceiveShutterInfo
    {
        public int[] receiveTime;
        public int[] receiveCount;
        public int[] reloadDspCardSeriesCount;
        public bool  isReceiveShutterStart;
        public int   receiveWaitCount;    public ReceiveShutterInfo(int maxBufferNumber)
        {
            isReceiveShutterStart = false;
    receiveWaitCount = 0;
            receiveTime = new int[maxBufferNumber];
    receiveCount = new int[maxBufferNumber];
    reloadDspCardSeriesCount = new int[maxBufferNumber];
    for (int i=0; i<maxBufferNumber; i++)
    {
        receiveTime[i] = GetTickCount();
        receiveCount[i] = 0; // Edit 2006-03-02 11:35
        reloadDspCardSeriesCount[i] = 0;
    }
        }
    }private const int MAX_IPSTRING_LENGTH = 32;
    private const int MAX_USERNAME_LENGTH = 32;
    private const int MAX_PWD_LENGTH = 32;
    private Struct XMLServerInfo 
    {  
        byte[] ServerIp;  
        uint   ServerPort;  
        byte[] UserName[]; 
        byte[] UserPwd[];      public XMLServerInfo()
        {
            ServerIp = new byte[MAX_IPSTRING_LENGTH];
            UserName = new byte[MAX_USERNAME_LENGTH]; 
            UserPwd  = new byte[MAX_PWD_LENGTH];
        } 

      

  13.   

    你在C下用sizeof得到大小,然后找对应的.net中的类型即可
      

  14.   

    现在要回到老问题了,我们如何调用(ActiveX)  http://download.csdn.net/user/lhsxsh 
     名称为“ActiveX控件在NET中的使用” 
    大家帮我测试下  
    AcsOpenStream(ref int acsHandle, ref int serverID, short u8AppID, int u32SendQSize, int u32RecvQSize, int s32DebugOn, ref int privateData);  
    方法中的 ref int serverID() 参数为ServerID_t的结构体   为怎么会变成  ref int serverID INT? NET程序要怎么写?C语言的代码    
    typedef struct  
    {  
    DJ_S8 m_s8ServerIp[32]; /*XMS server ip*/  
    DJ_U32 m_u32ServerPort; /*XMS server port*/  
    DJ_S8 m_s8UserName[32]; /**/  
    DJ_S8 m_s8UserPwd[32]; /**/  
    }ServerID_t;/**/  
    /**/  
    ServerID_t cfg_ServerID;  
      

  15.   

    AcsOpenStream(ref int acsHandle,ref IntPtr serverID, short u8AppID, int u32SendQSize, int u32RecvQSize, int s32DebugOn, ref int privateData);   Marshal.StructureToPtr