Solved

how to create resource in dll and use the resource in app?

Posted on 2003-11-10
1
308 Views
Last Modified: 2013-11-20
hi guys:
i am coding a small app,and write a dll (with mfc support) with a lot of text file in it.
i edit thedll.rc with notepad,add all text file in the rc file,such as
10002                   TEXTS   DISCARDABLE     "texts\\10002-first.txt"
in reource.h file,i do nothing.
the resource id is from 10002 to 30002(a huge one :));
my text file is acsii file and not more than 10kb.
in app,i use these code to load resource text:
            hRsrc=FindResource(hInstance,MAKEINTRESOURCE(10002),"TEXTS");
            hGlobal = LoadResource(hInstance, hRsrc);
            LPVOID pdata = LockResource(hGlobal);  
            LPBYTE sData = (LPBYTE)pdata;
            CString strTemp=(CString)(sData);
            FreeResource(hRsrc);
then compiled dll project and app project,all seems ok.
when the app running and load reosurce,sometimes it works fine,but sometimes it loads 2 or more text resources.(it loads 2 or three text files)
why? what's wrong with it?
can anyone tell me?
thank you guys ahead
johns
0
Comment
Question by:johnsmithz
1 Comment
 
LVL 3

Accepted Solution

by:
komar earned 50 total points
ID: 9720912
Hi,

Your code seem to be OK. But you are missing a call to SizeofResource() API which will help you determine the size of the resource you are looking for.
Here is what I suggest:

          hRsrc=FindResource(hInstance,MAKEINTRESOURCE(10002),"TEXTS");
          hGlobal = LoadResource(hInstance, hRsrc);

          TCHAR *szData = (TCHAR *)LockResource(h);
          DWORD dwSizeOfResource = SizeofResource(hRes, hr) / sizeof(TCHAR);

          CString strTemp;
          _tcsncpy(strTemp.GetBuffer(dwSizeOfResource), szData, dwSizeOfResource);
          strTemp.ReleaseBuffer(); //Data is now ready in strTemp

          FreeResource(hRsrc);

Thanks,
Khalid Omar.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 190
Detect CR LF to each line 12 170
Bartender label printing - switch on and off graphics 3 54
Problem to Office 1 15
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question