Title is No Title

not very good here!

导航

create dll formt lib with cpp funcs or c just funcs by hand.

1:write cpp or c style func head:

#define USECPP 
#include "comNet.h" //use put and get file.
    //because comNet are "c"
#pragma comment(lib,"Ws2_32.lib")

#define BUFSIZE 100
#define MAX_CMD_FILE_NAME_LEN 50
#define MAX_RESULT_FILE_NAME_LEN 50

#ifdef IMPDLL
#define DLL __declspec(dllimport)
#else
#define DLL __declspec(dllexport)
#endif
/*create dll

cl  dllNetClient.cpp -c
link dllNetClient.obj comNet.obj -dll 
*/
/*
BOOL APIENTRY DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
{
    return 1;
        UNREFERENCED_PARAMETER(hInst);
        UNREFERENCED_PARAMETER(ul_reason_being_called);
        UNREFERENCED_PARAMETER(lpReserved);
}
*/
DLL int commuWithServer(char *cmdFileName,SOCKET s,char *resultFileName);
DLL int sendCmdGetResutlFromToServer(char *cmdFileName,char *resultFileName,char *ipC,int portC);

2:write cpp or c source code.
3:compile:
cl dllNetClient.cpp -c
4:link into dll without tell anyting excep -dll
link dllNetClient.obj comNet.obj -dll
5:then will ok create dll and lib file.
6:testFile
#include "DllNetClient.h"
/*
cl testDllNetClient.cpp -c

link testDllNetClient.obj dllNetClient.lib
*/
int main(){
    char resultF[50];
 //1 ok,0,error.
    int ret=sendCmdGetResutlFromToServer("cmd2.txt",resultF,"127.0.0.1",5000);
 if(ret){
     printf("ok.\n");
 }else{
     printf("error.\n");
 }
 return 0;
}
7:compile and link.
link testDllNetClient.obj dllNetClient.lib

posted on 2005-07-15 12:50  abraham  阅读(392)  评论(0)    收藏  举报