put class into dll in dos by hand step by step

put class into dll is one of the questions that make me trouble utill one day
when I see <com inside>'s first chapter, I get the result.
and tried in dos cmd  and also VC6.
B:by hand in dos.
1:write TestCC.h
#ifdef IMPDLL
#define DLL __declspec(dllimport)
#else
#define DLL __declspec(dllexport)
#endif

class DLL TestCC{
public:
    void showMe();   
};
2:write TestCC.cpp
#include "stdio.h"
#include "TestCC.h"
void TestCC::showMe(){

    printf("ok,here is in dll./n");
}
3:write test use

#define IMPDLL

#include "TestCC.h"
int main(){
   
 TestCC c;
 c.showMe();
 return 0;

}
4:create exp and lib and def file(I can not understand realy,just try and get).
cl -c TestCC.cpp -oTestCC.dll
//althogh error,but can create lib file and other.
computer like:
D:/oracc>cl testCC.cpp -oTestCC.dll
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

testCC.cpp
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:testCC.exe
/out:TestCC.dll
testCC.obj
   Creating library TestCC.lib and object TestCC.exp
LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
TestCC.dll : fatal error LNK1120: 1 unresolved externals

5:link them and create dll.
link -entry:_DllMainCRTStartup@12 -dll TestCC.exp TestCC.lib TestCC.obj

msvcrt.lib
6:use it and ok.
D:/oracc>cl useTestCC2.cpp testCC.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

useTestCC2.cpp
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:useTestCC2.exe
useTestCC2.obj
testCC.lib

D:/oracc>useTestCC2
ok,here is in dll.
//------------------------------end by hand in dos.--------------------//

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值