Microsoft KB Archive/136997

= How to Run a Code Resource from a Visual C++ Application =

Article ID: 136997

Article Last Modified on 7/30/2001

-

APPLIES TO


 * Microsoft Visual C++ 4.0 Cross Development Edition for Macintosh

-



This article was previously published under Q136997



SUMMARY
This article illustrates loading and executing stand-alone Code Resources from a Visual C++ application using the sample code shipped with the Visual C++ Macintosh add-on.

Chapter 8 of the 68K Programmer's Guide in the Visual C++ Books Online discusses using stand-alone code and shared libraries in 68K programs. This chapter provides a brief set of instructions on how to call a code resource. For more information on Macintosh Code Resources, please refer to this chapter in the Books Online.



MORE INFORMATION
To load a Code Resource, the Macintosh System provides a function (GetResource) that will load any resources including code resources and return a handle to a code resource. Visual C++ provides a function (_PvApplyFixup) that will take a handle to a code resource and return a pointer to the entry point. You can use these two functions to run a code resource from a Visual C++ application. The following example demonstrates how to load and execute the SACODE sample's INIT code resource.

Step-by-Step Example
 Build the SACODE sample project located in Msvc20\Samples\M68k\Sacode and copy the resulting file to the Macintosh. Give the remote executable path and file name. For example:

Macintosh HD:Testing:SACODE Make a copy of the SKEL sample located in Msvc20\Samples\M68k\Skel and call it MYSKEL. Then, make the following modifications:

  Add an include for Resource.h in Skel.c. For example, after this line: #include 

add this line:

#include    Add a prototype for _PvApplyFixup and modify the DoAbout function to look like this: extern ProcPtr _PvApplyFixup(Handle);

DoAbout {     //   SetParamText (aboutStr); //  (void) Alert (aboutAlrt, nil); //  return 0;

Handle hResource; ProcPtr pCode;

hResource = GetResource('INIT',1);  // load the resource if (hResource != NULL)              // make sure it's loaded {          HLock(hResource);                    // lock down the handle pCode = _PvApplyFixup(hResource);   // get pointer to function pCode;                            // call the code resource HUnlock(hResource); }

return 0; }                                 Build the MYSKEL sample project, and copy the executable to the Macintosh. Give the remote executable path and file name. For example:

Macintosh HD:Testing:MYSKEL</li> Use a Macintosh resource editor application such as ResEdit to copy the INIT resource in the SACODE file to the MYSKEL executable.</li> Execute the MYSKEL program, and click About on the Help menu. The code resource will be executed, resulting in a series of five beeps.</li></ol>

Additional query words: kbinf 2.00

Keywords: KB136997

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.