Solved

EnumResourceTypes Function & C#

Posted on 2004-03-25
3
801 Views
Last Modified: 2012-06-27
Background: trying to grab some resources from a file. Take a look below, I need to know how to setup a callback function:

[DllImport("kernel32")]
private extern static long EnumResourceTypes(long hModule, long lpEnumFunc, long lParam);
[DllImport("kernel32")]
private extern static long EnumResTypeProc(long hModule, string lpszType, long lParam);

m_hMod = LoadLibraryEx(Filename, 0, LOAD_LIBRARY_AS_DATAFILE);
EnumResourceTypes(hModule, EnumResTypeProc(),0);

What do I need to do to get EnumResourceTypes to call the second variable as a callback function?
0
Comment
Question by:rossryan
  • 3
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10684981
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp09192002.asp
Functions with Callbacks

You don't need to import EnumResTypeProc. You should write it yourself and pass it's address to EnumResourceTypes.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10685011
Right EnumResourceTypes definition is:

[DllImport("kernel32")]
private extern static long EnumResourceTypes(IntPtr hModule, EnumResTypeProc callback, long lParam);

EnumResourceTypes is your delegate:

delegate bool EnumResourceTypes(
   IntPtr hModule,
   [MarshalAs(UnmanagedType.LPTStr)]
   string lpszType,
   long lParam);
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 10685036
Now write callback function according to delegate type:

bool EnumResourceTypesCallback(IntPtr hModule, string lpszType, long lParam)
{
    ...
}

And call EnumResourceTypes:

long result = EnumResourceTypes(hModule, new EnumResourceTypes(EnumResourceTypesCallback), lParam);
// (set hModule and lParam to required values).

Inplement required logic in EnumResourceTypesCallback function. Return 0 to stop enumeration, 1 to continue enumeration.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# 2015 Downloading text file and preserving the line breaks 5 38
Media.Imaging 1 18
Hey!!!! 1 22
HTML - Color not displaying correctly in EMAIL. 6 38
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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