您的位置:程序门 -> .net技术 -> c#



这个c++的dll我应该怎么导入函数?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


这个c++的dll我应该怎么导入函数?[已结贴,结贴人:bys_home]
发表于:2007-09-13 06:54:25 楼主
这个c++的dll我应该怎么导入函数?   特别是对const   struct   sockaddr*   name这样的参数的声明,我应该怎么做的?哪位高手帮我做一下?
#ifndef   _udt_h_
#define   _udt_h_


#ifndef   win32
      #include   <sys/types.h>
      #include   <sys/socket.h>
      #include   <netinet/in.h>
#else
      #include   <windows.h>
#endif
#include   <fstream>
#include   <set>
#include   <string>

#ifdef   win32
      //   explicitly   define   32-bit   and   64-bit   numbers
      typedef   __int32   int32_t;
      typedef   __int64   int64_t;
      typedef   unsigned   __int32   uint32_t;
      #if   _msc_ver   > =   1300
            typedef   unsigned   __int64   uint64_t;
      #else
            //   vc   6.0   does   not   support   unsigned   __int64:   may   bring   potential   problems.
            typedef   __int64   uint64_t;
      #endif

      #ifdef   udt_exports
            #define   udt_api   __declspec(dllexport)
      #else
            #define   udt_api   __declspec(dllimport)
      #endif
#else
      #define   udt_api
#endif

#define   no_busy_waiting


typedef   int   udtsocket;

typedef   std::set <udtsocket>   ud_set;
#define   ud_clr(u,   uset)   ((uset)-> erase(u))
#define   ud_isset(u,   uset)   ((uset)-> find(u)   !=   (uset)-> end())
#define   ud_set(u,   uset)   ((uset)-> insert(u))
#define   ud_zero(uset)   ((uset)-> clear())

enum   udtopt
{
      udt_mss,                           //   the   maximum   transfer   unit
      udt_sndsyn,                     //   if   sending   is   blocking
      udt_rcvsyn,                     //   if   receiving   is   blocking
      udt_cc,                             //   custom   congestion   control   algorithm
      udt_fc, //   flight   flag   size   (window   size)
      udt_sndbuf,                     //   maximum   buffer   in   sending   queue
      udt_rcvbuf,                     //   udt   receiving   buffer   size
      udt_linger,                     //   waiting   for   unsent   data   when   closing
      udp_sndbuf,                     //   udp   sending   buffer   size
      udp_rcvbuf,                     //   udp   receiving   buffer   size
      udt_maxmsg,                     //   maximum   datagram   message   size
      udt_msgttl,                     //   time-to-live   of   a   datagram   message
      udt_rendezvous,             //   rendezvous   connection   mode
      udt_sndtimeo,                 //   send()   timeout
      udt_rcvtimeo,                 //   recv()   timeout
      udt_reuseaddr //   reuse   an   existing   port   or   create   a   new   one
};

////////////////////////////////////////////////////////////////////////////////

struct   cperfmon
{
      //   global   measurements
      int64_t   mstimestamp;                                   //   time   since   the   udt   entity   is   started,   in   milliseconds
      int64_t   pktsenttotal;                                 //   total   number   of   sent   data   packets,   including   retransmissions
      int64_t   pktrecvtotal;                                 //   total   number   of   received   packets
      int   pktsndlosstotal;                                   //   total   number   of   lost   packets   (sender   side)
      int   pktrcvlosstotal;                                   //   total   number   of   lost   packets   (receiver   side)
      int   pktretranstotal;                                   //   total   number   of   retransmitted   packets
      int   pktsentacktotal;                                   //   total   number   of   sent   ack   packets
      int   pktrecvacktotal;                                   //   total   number   of   received   ack   packets
      int   pktsentnaktotal;                                   //   total   number   of   sent   nak   packets
      int   pktrecvnaktotal;                                   //   total   number   of   received   nak   packets

      //   local   measurements
      int64_t   pktsent;                                           //   number   of   sent   data   packets,   including   retransmissions
      int64_t   pktrecv;                                           //   number   of   received   packets
      int   pktsndloss;                                             //   number   of   lost   packets   (sender   side)
      int   pktrcvloss;                                             //   number   of   lost   packets   (receiverer   side)
      int   pktretrans;                                             //   number   of   retransmitted   packets
      int   pktsentack;                                             //   number   of   sent   ack   packets
      int   pktrecvack;                                             //   number   of   received   ack   packets
      int   pktsentnak;                                             //   number   of   sent   nak   packets
      int   pktrecvnak;                                             //   number   of   received   nak   packets
      double   mbpssendrate;                                   //   sending   rate   in   mb/s
      double   mbpsrecvrate;                                   //   receiving   rate   in   mb/s

      //   instant   measurements
      double   uspktsndperiod;                               //   packet   sending   period,   in   microseconds
      int   pktflowwindow;                                       //   flow   window   size,   in   number   of   packets
      int   pktcongestionwindow;                           //   congestion   window   size,   in   number   of   packets
      int   pktflightsize;                                       //   number   of   packets   on   flight
      double   msrtt;                                                 //   rtt,   in   milliseconds
      double   mbpsbandwidth;                                 //   estimated   bandwidth,   in   mb/s
      int   byteavailsndbuf;                                   //   available   udt   sender   buffer   size
      int   byteavailrcvbuf;                                   //   available   udt   receiver   buffer   size
};

class   cudtexception
{
public:
      cudtexception(int   major   =   0,   int   minor   =   0,   int   err   =   -1);
      cudtexception(const   cudtexception&   e);
      virtual   ~cudtexception();

            //   functionality:
            //         get   the   description   of   the   exception.
            //   parameters:
            //         none.
            //   returned   value:
            //         text   message   for   the   exception   description.

      virtual   const   char*   geterrormessage();

            //   functionality:
            //         get   the   system   errno   for   the   exception.
            //   parameters:
            //         none.
            //   returned   value:
            //         errno.

      virtual   const   int   geterrorcode()   const;

            //   functionality:
            //         clear   the   error   code.
            //   parameters:
            //         none.
            //   returned   value:
            //         none.

      virtual   void   clear();

private:
      int   m_imajor;                 //   major   exception   categories

//   0:   correct   condition
//   1:   network   setup   exception
//   2:   network   connection   broken
//   3:   memory   exception
//   4:   file   exception
//   5:   method   not   supported
//   6+:   undefined   error

      int   m_iminor; //   for   specific   error   reasons
      int   m_ierrno; //   errno   returned   by   the   system   if   there   is   any
      std::string   m_strmsg; //   text   error   message

public:   //   error   code
      static   const   int   success;
      static   const   int   econnsetup;
      static   const   int   enoserver;
      static   const   int   econnrej;
      static   const   int   esockfail;
      static   const   int   esecfail;
      static   const   int   econnfail;
      static   const   int   econnlost;
      static   const   int   enoconn;
      static   const   int   eresource;
      static   const   int   ethread;
      static   const   int   enobuf;
      static   const   int   efile;
      static   const   int   einvrdoff;
      static   const   int   erdperm;
      static   const   int   einvwroff;
      static   const   int   ewrperm;
      static   const   int   einvop;
      static   const   int   eboundsock;
      static   const   int   econnsock;
      static   const   int   einvparam;
      static   const   int   einvsock;
      static   const   int   eunboundsock;
      static   const   int   enolisten;
      static   const   int   erdvnoserv;
      static   const   int   erdvunbound;
      static   const   int   estreamill;
      static   const   int   edgramill;
      static   const   int   easyncfail;
      static   const   int   easyncsnd;
      static   const   int   easyncrcv;
      static   const   int   eunknown;
};
发表于:2007-09-13 06:54:331楼 得分:0
namespace   udt
{
typedef   cudtexception   errorinfo;
typedef   udtopt   sockopt;
typedef   cperfmon   traceinfo;
typedef   ud_set   udset;

udt_api   extern   const   udtsocket   invalid_sock;
#undef   error
udt_api   extern   const   int   error;

udt_api   udtsocket   socket(int   af,   int   type,   int   protocol);

udt_api   int   bind(udtsocket   u,   const   struct   sockaddr*   name,   int   namelen);

udt_api   int   listen(udtsocket   u,   int   backlog);

udt_api   udtsocket   accept(udtsocket   u,   struct   sockaddr*   addr,   int*   addrlen);

udt_api   int   connect(udtsocket   u,   const   struct   sockaddr*   name,   int   namelen);

udt_api   int   close(udtsocket   u);

udt_api   int   getpeername(udtsocket   u,   struct   sockaddr*   name,   int*   namelen);

udt_api   int   getsockname(udtsocket   u,   struct   sockaddr*   name,   int*   namelen);

udt_api   int   getsockopt(udtsocket   u,   int   level,   sockopt   optname,   void*   optval,   int*   optlen);

udt_api   int   setsockopt(udtsocket   u,   int   level,   sockopt   optname,   const   void*   optval,   int   optlen);

udt_api   int   send(udtsocket   u,   const   char*   buf,   int   len,   int   flags);

udt_api   int   recv(udtsocket   u,   char*   buf,   int   len,   int   flags);

udt_api   int   sendmsg(udtsocket   u,   const   char*   buf,   int   len,   int   ttl   =   -1,   bool   inorder   =   false);

udt_api   int   recvmsg(udtsocket   u,   char*   buf,   int   len);

udt_api   int64_t   sendfile(udtsocket   u,   std::ifstream&   ifs,   int64_t   offset,   int64_t   size,   int   block   =   366000);

udt_api   int64_t   recvfile(udtsocket   u,   std::ofstream&   ofs,   int64_t   offset,   int64_t   size,   int   block   =   7320000);

udt_api   int   select(int   nfds,   udset*   readfds,   udset*   writefds,   udset*   exceptfds,   const   struct   timeval*   timeout);

udt_api   errorinfo&   getlasterror();

udt_api   int   perfmon(udtsocket   u,   traceinfo*   perf,   bool   clear   =   true);
}

#endif
发表于:2007-09-13 10:48:542楼 得分:0
up
发表于:2007-09-13 12:45:173楼 得分:20
我写了个代理类,只要设置一下导出函数的定义即可,源码可去这里下载:
http://bbs.chinaitlab.com/frame.php?frameon=yes&referer=http%3a//bbs.chinaitlab.com/thread-252229-1-1.html
发表于:2007-09-13 14:37:254楼 得分:0
我就是不知道怎么声明这个函数的啦,你的那个,还是要映射到方法上的么,


快速检索

最新资讯
热门点击