(1)file->new->project->dynamic link library;
名字:dynamiclib
将工程自动生成的main.cpp文件删除,自动添加一个.c文件(trydll.c) 将main.h 文件删除 创建一个trydll.h文件:
trydll.c:
#include <stdio.h> #include <string.h> #include "trydll.h" void hello(){ printf("hello\n"); printf("xd"); }
#ifndef __TRYDLL_H__INCLUDED #define __TRYDLL_H__INCLUDED #include <windows.h> /* To use this exported function of dll, include this header * in your project. */ #ifdef BUILD_DLL #define DLL_EXPORT __declspec(dllexport) #else #define DLL_EXPORT __declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif void DLL_EXPORT hello(); #ifdef __cplusplus } #endif #endif // __trydll_H__
\dynamiclib\bin\Debug下:
#include <stdio.h> #include <stdlib.h> #include "trydll.h" int main() { hello(); printf("Hello world!\n"); return 0; }结果:
原文地址:http://blog.csdn.net/xd_122/article/details/40866185