c/c++编写DLL求救

GJA106 2009-08-06 06:16:28
项目要求编写一个DLL组件,要求如下:
1.方法名大家随意编写;
2.入参:int type,char *name,char *product
出参:int result,double circle,char *version

3.提供完整代码,包括调用demo


谢谢各位GG、MM。
...全文
204 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
GJA106 2009-08-07
  • 打赏
  • 举报
回复
确实很简单!没办法,我手中没有精通c/c++的资源。
码侬 2009-08-06
  • 打赏
  • 举报
回复
接分就好了
rendao0563 2009-08-06
  • 打赏
  • 举报
回复
果然都是重赏之下必有勇夫啊
ljz888666555 2009-08-06
  • 打赏
  • 举报
回复
应该是个COM组件。
雪影 2009-08-06
  • 打赏
  • 举报
回复
感觉太简单了 200分啊
  • 打赏
  • 举报
回复
楼主说的不 只是一个DLL这么简单吧
oyljerry 2009-08-06
  • 打赏
  • 举报
回复
如果是COM组件,那么接口参数还要修改,要么就做成标准Windows DLL,参数用基本类型,那么一般的语言还有一些办法调用..
副组长 2009-08-06
  • 打赏
  • 举报
回复
不会吧,LZ说的是DLL组件。是不是需要一个供其它语言使用的COM?
雪影 2009-08-06
  • 打赏
  • 举报
回复
#include <windows.h>
#include <iostream>
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
return TRUE;
}
__declspec(dllexport) int fnTest(int type, char* name, char* product, int* result, double* circle, char* version)
{
printf("input type(%d), name(%s), product(%s)", type, name, product);
if (result) *result = 10;
if (circle) *circle = 0.3;
if (version) strcpy(version, "1.3.8");
return 0;
}


__declspec(dllimport) int fnTest(int type, char* name, char* product, int* result, double* circle, char* version);
void main()
{
int result;
double circle;
char version[20];
foo(1, "myname", "myproduct", &result, &circle, version);
}
qqiuzaihui 2009-08-06
  • 打赏
  • 举报
回复
如果要我刚才写的实例代码, 发邮件至: qiuzaihui@163.com 中索取.
qqiuzaihui 2009-08-06
  • 打赏
  • 举报
回复
// 测试程序中(MFC程序):

1. 在头文件中声明一个结构体:
struct _MY_CUSTOM_
{
int result;
double circle;
char* version;
};


2. 创建一个结构体实例:
struct _MY_CUSTOM_ myCustom;

3. 测试代码:
HINSTANCE hInst = LoadLibrary("HmPark.dll");
typedef _MY_CUSTOM_ (CALLBACK *ADDPROC)(int type, char* name, char* product);
ADDPROC MyCustomFunction = (ADDPROC)GetProcAddress(hInst, "MyCustomFunction");

if( !MyCustomFunction )
{
MessageBox("找不到动态库");
return;
}

char* name = "my";
char* product = "custom";
int type = 5;
CString str;

try
{
myCustom = MyCustomFunction(type, name, product);
}
catch(...)
{
MessageBox("Error");
}

str.Format("\n%d, %f, %s.\n", myCustom.result, myCustom.circle, myCustom.version );
MessageBox( str );

输出结果: 5, 10.000000, my.

以上代码在VS2005中调试通过.
qqiuzaihui 2009-08-06
  • 打赏
  • 举报
回复
// 刚临时写了一个, 供你参考:

// ParkLib.def 文件内容
; ParkLib.def : Declares the module parameters for the DLL.

LIBRARY "ParkLib"
DESCRIPTION 'ParkLib Windows Dynamic Link Library'

EXPORTS
; Explicit exports can go here
MyCustomFunction




/*****************************************************************************/
// ParkLib.h 文件内容

/*--------------------------------------------------------------------------
ParkLib.H header file
----------------------------------------------------------------------------*/
#ifdef __ParkStdFee
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif

/******************************************************************************
*
* 自定义一个数据结构用于返回
*
******************************************************************************/
typedef struct
{
int result;
double circle;
char* version;
}_MY_CUSTOM_;


/******************************************************************************
*
* 函数功能:根据输入的 [type] ,[name] 及 [product] 返回结果
* 输 入:[type] ,[name] 及 [product]
* 返 回:_MY_CUSTOM_ 结构数据
*
******************************************************************************/
EXPORT _MY_CUSTOM_ CALLBACK MyCustomFunction(int type, char* name, char* product);





/*****************************************************************************/
// ParkLib.C 文件内容

/*---------------------------------------------------------------------------
ParkLib.C -- Easy Drawing Routine Library module

-----------------------------------------------------------------------------*/
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include "ParkLib.h"

_MY_CUSTOM_ CALLBACK MyCustomFunction(int type, char* name, char* product); //自定义函数

int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
return TRUE ;
}

EXPORT _MY_CUSTOM_ CALLBACK MyCustomFunction(int type, char* name, char* product)
{
_MY_CUSTOM_ myCustom;

myCustom.result = type;
myCustom.circle = type * 2;
myCustom.version = name;

return myCustom;
}
jameshooo 2009-08-06
  • 打赏
  • 举报
回复
出参至少都得是缓冲区指针吧,比如
int foo(int type, char* name, char* product, int* result, double* circle, char* version)
{
printf("input type(%d), name(%s), product(%s)", type, name, product);
if (result) *result = 10;
if (circle) *circle = 0.3;
if (version) strcpy(version, "1.3.8");
return 0;
}

main()
{
int result;
double circle;
char version[20];
foo(1, "myname", "myproduct", &result, &circle, version);
}

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧