在DLL里使用图片资源文件出问题了

zjsyw 2005-10-20 09:14:26
我在做一个软件的时候有几个图片资源(bmp)放在程序里用下面的get_picture()运行很正常,但是图片太大了,于是我想放到DLL里(dll源程序如下),可是编译过了,调用DLL里的get_picture函数却在 bitmap->LoadFromResourceName((int)HInstance,"SRC1");//这里停住了,下面一句不执行了。哪位朋友帮我看看
//---------------------------------------------------------------------------

#include <windows.h>
#include <jpeg.hpp>
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------
#pragma argsused
#pragma resource "source.res" //这是我的资源文件
extern "C" __declspec(dllexport) void __stdcall get_picture();
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------

void __stdcall get_picture()
{
Graphics::TBitmap *bitmap=new Graphics::TBitmap;
bitmap->LoadFromResourceName((int)HInstance,"SRC1");//这里停住了
bitmap->SaveToFile("c:\\xy_temp.bmp");
delete bitmap;
}
...全文
168 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
CACACACACA 2005-10-20
  • 打赏
  • 举报
回复
project->add to project加入.rc文件。

然后Project->Builde就生成.dll文件了。
constantine 2005-10-20
  • 打赏
  • 举报
回复
project->add to project
读图片的函数不用放到dll里面,dll就放资源就行了
zjsyw 2005-10-20
  • 打赏
  • 举报
回复
把.rc文件加入后编译为dll文件。
rc文件可以直接加入而不需要编译成res资源文件加入吗?怎么加?
CACACACACA 2005-10-20
  • 打赏
  • 举报
回复
bmp.rc文件如下:

a RT_BITMAP aa.bmp
b RT_BITMAP bb.bmp
c RT_BITMAP cc.bmp

用BCB成成dll文件如下。

//---------------------------------------------------------------------------

#include <windows.h>
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------

#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}

把.rc文件加入后编译为dll文件。
//---------------------------------------------------------------------------

//调用如下
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE h = LoadLibrary("Project1.dll");
TResourceStream *r = new TResourceStream( (int)h, "a", "RT_BITMAP" );
r->SaveToFile("ttt.bmp");
}
//---------------------------------------------------------------------------

13,826

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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