Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-11-10
1
Medium Priority
?
318 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 150 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Loops Section Overview
Suggested Courses

782 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