注册 登录
编程论坛 C++教室

在VC++中怎么把自己写的C++代码生成.dll文件

fangfangff 发布于 2007-09-16 21:11, 1268 次点击
在VC++中怎么把自己写的C++代码生成.dll文件,
在该怎么建工程呢??还有文件也怎么建呢??
建这些的步骤是怎么样的啊??可以讲解一下吗??
请各位高手帮帮忙哈!!
在此先谢谢了!
谢谢哈!!
8 回复
#2
雨中飞燕2007-09-16 21:20
建立一个Dll的工程



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

[url=http://bbs.bc-cn.net/viewthread.php?tid=163571]请大家不要用TC来学习C语言,点击此处查看原因[/url]
[url=http://bbs.bc-cn.net/viewthread.php?tid=162918]C++编写的Windows界面游戏[/url]
[url=http://yzfy.org/]C/C++算法习题(OnlineJudge):[/url] http://yzfy.org/
#3
fangfangff2007-09-16 21:33

大体的过程是怎么样的啊???
我也不太明白怎么建立啊!!!
谢谢你哈!!

#4
HJin2007-09-16 23:02
回复:(fangfangff)在VC++中怎么把自己写的C++代码生...

I will explain what you need to do on a windows system.

Step 1: (file name is helloDLL.c)

程序代码:

/**
File: helloDLL.c


To make a .DLL file, compile it with


cl /LD helloDLL.c


The above is for MS complier. You may
complier's command may be different.
*/


#include <stdio.h>


__declspec(dllexport) void hello_world()
{
    printf(\"Hello, world.\n\");
}



run cl /LD helloDLL.c to make the DLL and Lib;

Step 2: (file name is callDll.c)
程序代码:

// cl callDll.c


#include <windows.h>


int main()
{
    HINSTANCE hLib;
    void (*funcPointer)(void); // funcPointer can be named anything


    hLib = LoadLibrary(\"helloDLL.DLL\");
    funcPointer = (void (*)(void))GetProcAddress(hLib, \"hello_world\");
    funcPointer();


    return 0;
}


run cl callDll.c to make a .exe file --- you can run the .exe file after compilation. Here we dynamically linked against library helloDLL.DLL;

Step3 (filename is callLib.c)

// compile by command: cl callLib.c helloDll.lib


void hello_world();


int main()
{
    hello_world();
   
    return 0;
}



run cl callLib.c helloDll.lib to make .exe file --- you can run the .exe file after compilation. Here we statically linked against the library file helloDll.lib.

The above is MS stuff: windows system with MS VC. If you are using Linux/Unix or the complier is gcc/g++, you need to make some changes.

HJin



#5
fangfangff2007-09-17 12:56
谢谢你哈!!
你是不是从国外来的呢??
怎么都是英文的啊
这个我看得不懂
我叫别人帮忙翻译一下就可以了
谢谢哈!!
#6
冰的热度2007-09-17 18:23

VC++6.0的向导选项卡里有.MFC AppWizard(dll)和Win32 Dynamic-Link Library

用这两个来建

#7
fangfangff2007-09-17 21:33
回复:(冰的热度)VC++6.0的向导选项卡里有.MFC AppW...

这样的话怎么建呢??
是不是直接建了就可以了啊
有没有什么特殊的过程和设置的吗???
#8
雨中飞燕2007-09-17 21:42
以下是引用fangfangff在2007-9-17 21:33:32的发言:

这样的话怎么建呢??
是不是直接建了就可以了啊
有没有什么特殊的过程和设置的吗???

请问你自己动手试了没有?需要找个人手把手教你吗??
别人不是已经告诉了你建立什么工程吗?
建立个工程都不会自己去试,那你怎么学下去?



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

[url=http://bbs.bc-cn.net/viewthread.php?tid=163571]请大家不要用TC来学习C语言,点击此处查看原因[/url]
[url=http://bbs.bc-cn.net/viewthread.php?tid=162918]C++编写的Windows界面游戏[/url]
[url=http://yzfy.org/]C/C++算法习题(OnlineJudge):[/url] http://yzfy.org/

#9
踏魔狼2007-09-17 21:52

呵呵!

1