Solved

EnumResourceTypes Function & C#

Posted on 2004-03-25
3
796 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Needing an event fired when a row is added on a datagridview 4 36
Visual Studio 2013 debugging 2 35
Error on link 14 39
Help with C#, MVC, razor. 6 23
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now