我有一个dll文件,里面有两个方法,因为用到std::ifstream无法在C#中引用, 
所以我需要重新做一个dll,用于改写这个dll的参数,在dll内部完成。 
原dll名称transport.dll里有方法 
#define UDT_API __declspec(dllimport) 
typedef __int64 int64_t; 
typedef int UDTSOCKET; 
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); 我要实现的dll名称为transportfile.dll,是套在原dll之上的一个dll,只实 
现里面原有两个方法的参数修改,修改后的如下 
UDT_API int64_t udtsendfile(UDTSOCKET u, char* filename); 
UDT_API int64_t udtrecvfile(UDTSOCKET u, char* filename, int64_t size); 实现分别如下 
int64_t udtsendfile(UDTSOCKET u, char* filename) 

// open the file 
   ifstream ifs(filename, ios::in  ¦ ios::binary);    ifs.seekg(0, ios::end); 
   int64_t size = ifs.tellg(); 
   ifs.seekg(0, ios::beg); 
   int64_t result; 
   result = sendfile(u, ifs, 0, size); 
   ifs.close(); 
   return result; 

int64_t udtrecvfile(UDTSOCKET u, char* filename, int64_t size) 

   ofstream ofs(filename, ios::out  ¦ ios::binary  ¦ ios::trunc); 
   int64_t recvsize;  
   recvsize=recvfile(u, ofs, 0, size); 
   ofs.close(); 
   return recvsize; 
}要求:这个dll还是要输出的,因为我要在c#中引用 如果需要我可以提供原始dll
我的QQ:172036637 MSN:[email protected]
在线等,

解决方案 »

  1.   

    新dll的接口
    long init(); //初始化UDTSOCKET,并返回操作句柄,如果dll内部是用类实现的,则返回类的指针,否则返回socket
    void fini(long_handle handle); //销毁
    int64_t send_file(long_handle handle, char* filename); //发送文件
    int64_t recv_file(long_handle handle, char* filename, int64_t size); //接收文件
      

  2.   

    动态导入dll:(实在没理解“彼动态导入dll”是什么意思)
    typedef int64_t (UDT_API *SendFunc)(UDTSOCKET , std::ifstream& , int64_t, int64_t, int);  HMODULE hDLL = LoadLibrary("transport.dll");
    if( hDLL == NULL )
    {
        MessageBox("Load library failed!");
        return;
    }SendFunc pSend = (SendFunc)GetProcAddress(hDLL, "sendfile");
    if( pSend == NULL )
    {
        MessageBox("Export symbol \"sendfile\" not found!");
        return;
    }//int64_t udtsendfile(UDTSOCKET u, char* filename)  
    //{  
    // open the file  
       ifstream ifs(filename, ios::in  ¦ ios::binary);     ifs.seekg(0, ios::end);  
       int64_t size = ifs.tellg();  
       ifs.seekg(0, ios::beg);  
       int64_t result;  
       result = pSend(u, ifs, 0, size);  
       ifs.close();  
    //   return result;  
    //}  FreeLibrary(hDLL);
    return result;
      

  3.   

    typedef int64_t (UDT_API *SendFunc)(UDTSOCKET , std::ifstream& , int64_t, int64_t, int);  HMODULE hDLL = LoadLibrary("transport.dll");
    if( hDLL == NULL )
    {
        MessageBox("Load library failed!");
        return;
    }SendFunc pSend = (SendFunc)GetProcAddress(hDLL, "sendfile");
    if( pSend == NULL )
    {
        MessageBox("Export symbol \"sendfile\" not found!");
        return;
    }//int64_t udtsendfile(UDTSOCKET u, char* filename)  
    //{  
    // open the file  
       ifstream ifs(filename, ios::in  ¦ ios::binary);     ifs.seekg(0, ios::end);  
       int64_t size = ifs.tellg();  
       ifs.seekg(0, ios::beg);  
       int64_t result;  
       result = pSend(u, ifs, 0, size);  
       ifs.close();  
    //   return result;  
    //}  FreeLibrary(hDLL);
    return result;===============
    ding