全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:4813
推到 Plurk!
推到 Facebook!

將程式放入資源檔

答題得分者是:RaynorPao
firewing
一般會員


發表:23
回覆:47
積分:19
註冊:2002-12-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-03-26 09:35:24 IP:139.223.xxx.xxx 未訂閱
請問一下: 若我將某一個副程式寫成 dll 檔,但我最後只想要有一個 .exe 的執行檔而已,不想再附 dll 檔給 user 那我可以將 dll 包進我的 資源檔嗎??? 請問該如何寫??? 謝謝各位大大....
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-03-26 09:51:22 IP:203.73.xxx.xxx 未訂閱
引言: 請問一下: 若我將某一個副程式寫成 dll 檔,但我最後只想要有一個 .exe 的執行檔而已,不想再附 dll 檔給 user 那我可以將 dll 包進我的 資源檔嗎??? 請問該如何寫??? 謝謝各位大大....
firewing 你好:
(1)你的想法,理論上是可行的
(>
備註:

        
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
firewing
一般會員


發表:23
回覆:47
積分:19
註冊:2002-12-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-03-26 10:10:03 IP:139.223.xxx.xxx 未訂閱
RaynorPao 兄: 謝謝你,我會試試看,可以再問你一下嗎??? A1------------WAV-----------wav1.Wav B1------------CURSOR--------cursor1.cur C1------------ICON----------icone1.ico D1------------BITMAP--------title.bmp E1------------EXEFILE-------pkunzip.exe ↓---------------↓--------------↓ 可-------------keyWord---------檔案路徑 照自已喜愛取名 (不好意思我不會用空格所以用"-"代替) 那我 *.rc 該怎麼寫呢??? 再 keyWord 的這個部分, 是不是 DLL 即可... KeyWord 有它固定的寫法嗎??? 發表人 - firewing 於 2003/03/26 10:26:38
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-03-26 10:42:17 IP:61.218.xxx.xxx 未訂閱

Playing wave resources

by 「Kent Reisdorph 」 Most of the time, you play wave audio from a file on disk. Sometimes, however, you want to be able to play a sound contained as a resource. The resource might be in a DLL, or it might be in your EXE. This article will show you how to bind a wave audio resource to your EXE and how to play that wave resource at runtime. Creating the resource In order to bind a wave audio resource to your EXE, you must create a resource script (RC) file. A resource script file is nothing more than a text file with an extension of RC, containing text in a format that can be read by C Builder's resource compiler. By far the easiest way of getting wave audio data into an executable is to start with a wave file on disk. Then, you can create a wave resource with a single line in the RC file: MY_WAVE_RESOURCE WAVE "chimes.wav" That's it! The format for creating a custom resource is as follows: RESNAME RESTYPE FILENAME To create a resource script file, create a new text file from the C Builder Object Repository. Enter your resource text in the blank file, then save the file with an RC extension. (Don't forget to remove the default *.TXT extension in the File Save dialog box or you'll end up with a filename that looks like MYRES.TXT.RC.) Here's a sample RC file that defines four wave resources: // RESNAME RESTYPE FILENAME // --------------------------------------- CHIMES Wave "chimes.wav" CHORD Wave "chord.wav" DING Wave "ding.wav" TADA Wave "tada.wav" (We put comments in the file so you could see the format of the resources, but they aren't necessary.) You'll typically see resource names in all uppercase, but that isn't a requirement. In fact, it doesn't matter whether you use uppercase or lowercase, because resource names aren't case sensitive. Binding the resources to the EXE Binding the resources to the EXE sounds like a big job. In reality, doing so requires nothing more than adding the RC file you just created to your application's project. Simply use C Builder's Add To Project option and add the resource script to your project. The next time you compile your application, the resource script file will be compiled (by the resource compiler) and bound to your EXE (or DLL, if you have a DLL project). Be sure your resource file doesn't contain errors. If the resource compiler encounters errors, you'll get a message like the following: [RCError] Wave.RC(4): Cannot open file: Wave. [RCFatal Error] Compile. The format for specifying wave resources in RC files is pretty basic, so you shouldn't have problems with resource compiler errors. Naturally, you'll want to check that any wave files referenced in your resource script are in your project directory, or that you fully qualify the path to the wave file. Tip: Quick resource compile If you have C Builder 3.0, you can right-click on the RC file in the Project Manager to compile the resource file. Putting the wave resource to work Now that you have a wave resource bound to your EXE, you can put it to work. There are two ways to play a wave file contained as a resource. Let's take a look. The easy way It's easiest to play a sound resource by using the Windows API function PlaySound. (We discussed PlaySound last month in the article "Low-level Wave Audio, Part 1.") Here's how the code looks: PlaySound("Chimes", HInstance, SND_RESOURCE); You didn't know it would be so easy, did you? Note that the resource name is passed as the first parameter to PlaySound. The second parameter is the instance handle to the module that contains the wave resource. In this case, we use HInstance to tell Windows to look in the EXE for the wave resource. If your wave resources are contained in a DLL, you can load the DLL using LoadLibrary and use the returned instance handle in your call to PlaySound. For example: HINSTANCE dllInstance; dllInstance = LoadLibrary("myres.dll"); PlaySound("raygun", dllInstance, SND_RESOURCE); The final parameter of PlaySound can contain many flags, but you must specify the SND_RESOURCE flag in addition to any other flags you provide. This flag tells Windows that the sound you're playing is a resource ( as opposed to a file on disk or an alias for a system sound). The hard way The hard way to play a sound resource involves using the low-level wave audio functions as discussed in the article, "Low-level Wave Audio, Part 2." You won't typically have to go to this extent to play wave resources, but sometimes it's necessary. For example, TAPI (the telephony API) allows you to play a wave file through a voice modem. The mechanism specified by TAPI for playing wave files uses the low-level wave audio functions (waveOutOpen and others). Hence, if you want to use wave resources with TAPI, you must go to the trouble of implementing the low-level wave audio functions. The TResourceStream class is great for loading a resource into memory. Once it's loaded, you can manipulate the resource as needed. Here's the code to load the CHIMES resource used in the previous example: TResourceStream* res = new TResourceStream( (int)HInstance, "CHIMES", "Wave"); The TResourceStream constructor takes three parameters. The first parameter is the instance handle of the module that contains the resource. In this case, the instance handle must be cast to an int because VCL expects the instance handle to be an integer. The second parameter is the name of the resource to load, and the final parameter is the resource type as defined in the RC file. Now that you have the wave resource loaded into memory, you can copy the important bits of data from the resource stream. A wave file in memory is, of course, in a pre-defined format. The format is identical to a wave file stored on disk. You can go the hard way and use mmioOpen to open the resource as a memory-mapped file, or you can just cheat a little and locate the wave format header and wave data using TResourceStream. For example, here's how to read the wave format header of a wave resource:
    // Locate the fmt chunk.
int x, i;
int ckid = mmioStringToFOURCC("fmt ", 0);
for (i=0;i<100;i  ) {
  res->Read(&x, 4);
  if (x == ckid) break;
  res->Position -= 3;
}
// Read the size of the format data.
int size;
res->Read(&size, 4);
// Read the wave format.
memset(&WaveFmt, 0, sizeof(WAVEFORMATEX));
res->Read(&WaveFmt, size);
You can do the same thing to read the actual wave data. For instance, the ResourceChange method in Listing A of the accompanying article, "Low-level Wave Audio, Part 2," shows how you can load a wave resource into a buffer in preparation for playback. Once you've loaded the wave format header and loaded the wave data into a buffer, you can play the wave data using the low-level audio functions as described in the accompanying article. Conclusion Playing a wave resource isn't difficult once you know how to go about it. Whenever possible, you should opt for the easy way and use the PlaySound function to play the wave resource. When nothing else will do, though, the low-level wave audio functions provide an alternate means of playing a wave resource. Copyright ?2003, Bridges Publishing. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Bridges Publishing is prohibited. All other product names and logos are trademarks or registered trademarks of their respective owners. 聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]--- 發表人 - axsoft 於 2003/03/26 10:44:05
firewing
一般會員


發表:23
回覆:47
積分:19
註冊:2002-12-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-03-28 12:58:50 IP:139.223.xxx.xxx 未訂閱
RaynorPao 兄: 不好意思,對於你的第三,第四項我還不太了解 可否說的更清楚一點???
integrand
一般會員


發表:8
回覆:27
積分:17
註冊:2002-10-22

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-03-29 12:23:14 IP:218.160.xxx.xxx 未訂閱
引言: RaynorPao 兄: 不好意思,對於你的第三,第四項我還不太了解 可否說的更清楚一點???
RaynorPao的意思我覺得應該是說 把DLL檔當作一般的二進位資料放在Resource resource型態用 RC_DATA 等程式執行的時候 再把那些資料存成暫存的DLL檔 然後再用一般連結DLL的方法連結它 等程式執行完後再刪掉 不知道你的情況是如何 不過改成靜態連結真的會比較麻煩嗎?
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-03-31 11:20:12 IP:203.73.xxx.xxx 未訂閱
引言: RaynorPao 兄: 不好意思,對於你的第三,第四項我還不太了解 可否說的更清楚一點???
firewing 你好:
試出來了嗎?? 我把整個過程寫下來好了(我的做法)
(>>>    -- 
        
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
firewing
一般會員


發表:23
回覆:47
積分:19
註冊:2002-12-13

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-03-31 11:21:32 IP:139.223.xxx.xxx 未訂閱
引言: RaynorPao的意思我覺得應該是說 把DLL檔當作一般的二進位資料放在Resource resource型態用 RC_DATA 等程式執行的時候 再把那些資料存成暫存的DLL檔 然後再用一般連結DLL的方法連結它 等程式執行完後再刪掉 不知道你的情況是如何 不過改成靜態連結真的會比較麻煩嗎?
integrand 兄: 請問用靜態連結後是不是就不需要在附上 dll 檔給 user 呢???
firewing
一般會員


發表:23
回覆:47
積分:19
註冊:2002-12-13

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-03-31 11:30:32 IP:139.223.xxx.xxx 未訂閱
RaynorPao 兄: 不好意思,我沒有 Virtual C 這套軟體ㄟ.... 所以大概沒辦法照你所說的做.... 不過還是謝謝你這麼熱心的為我解答.. 謝謝
integrand
一般會員


發表:8
回覆:27
積分:17
註冊:2002-10-22

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-03-31 18:01:28 IP:218.160.xxx.xxx 未訂閱
引言: integrand 兄: 請問用靜態連結後是不是就不需要在附上 dll 檔給 user 呢???
哀...在下還年輕 就別叫我兄了 我必須承認我從來沒寫過靜態連結函式庫 很久以前當我第一次看到電腦實體還沒超過一個月 學校的計算機概論教的是C語言 根據我印象中那時候老師的說法 連結lib檔的函式庫 會把用到的機器碼加到執行檔 這應該就是所謂的靜態連結 編譯時期的連結 所以就不必附上該函式庫 我想既然你的dll函式庫是自己寫的 如果不麻煩的話 不如把它重新寫成lib函式庫
integrand
一般會員


發表:8
回覆:27
積分:17
註冊:2002-10-22

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-03-31 18:38:38 IP:218.160.xxx.xxx 未訂閱
引言: RaynorPao 兄: 不好意思,我沒有 Visual C 這套軟體ㄟ.... 所以大概沒辦法照你所說的做.... 不過還是謝謝你這麼熱心的為我解答.. 謝謝
其實RaynorPao的作法 只有在產生rc檔的時候用到VC 而這部份也不一定要用VC 只是VC 在資源檔編輯這方面有比較好的工具 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tools/tools/resource_compiler.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tools/tools/rcdata_resource.asp 用手動的話 開個新檔寫入 IDR_DATA1 RC_DATA "BcbDll.dll" 然後存成bcbdll.rc 放在bcbdll.dll同一個目錄下 至於IDR_DATA1應該define一個常數比較好 不過設多少我也沒啥概念 然後用Project->Add to Project在執行檔專案加入那個rc檔 其他的照原來的方法應該就行了 當然.....以上純屬想像 沒試過也不知道會有啥錯誤^^
firewing
一般會員


發表:23
回覆:47
積分:19
註冊:2002-12-13

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-04-01 09:09:56 IP:139.223.xxx.xxx 未訂閱
RaynorPao 兄: 不好意思再請教你一下.... 若要在沒安裝 BCB 的電腦上執行 BCB 的程式時, 必須在 compilier 時候要將 Use dynamic RTL 取消, Build with runtime packages 也取消,這是不是代表 不需 BCB 的設定檔和 dll 檔,那是不是也可以將我的 dll 程式也包含進去呢???
firewing
一般會員


發表:23
回覆:47
積分:19
註冊:2002-12-13

發送簡訊給我
#13 引用回覆 回覆 發表時間:2003-04-01 09:11:09 IP:139.223.xxx.xxx 未訂閱
integrand : 謝謝你的回答....
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#14 引用回覆 回覆 發表時間:2003-04-01 09:17:14 IP:203.73.xxx.xxx 未訂閱
引言: RaynorPao 兄: 不好意思再請教你一下.... 若要在沒安裝 BCB 的電腦上執行 BCB 的程式時, 必須在 compilier 時候要將 Use dynamic RTL 取消, Build with runtime packages 也取消,這是不是代表 不需 BCB 的設定檔和 dll 檔,那是不是也可以將我的 dll 程式也包含進去呢???
firewing 你好:
(1)那是針對 VCL 的部分(包括 Borland 提供的,也包括你自己寫的元件)
(2)但是並不包括你寫的 DLL, OCX, ....
(3)那個 DLL 如果是你自己寫的話,那代表你一定有 Source Code,你可以把它
   轉成 Win32 Static Library,Compile 出來會是一個 LIB,再把這個 LIB
   加入到要使用的專案中,就不會有上述的問題了
-- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
系統時間:2024-11-23 0:44:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!