Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1868026
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:38:03+00:00 2026-05-17T06:38:03+00:00

I am wondering if there is a cleaner way to write the ( working

  • 0

I am wondering if there is a cleaner way to write the (working) code below:

uint uEnum = 0;
PStore.EnumTypes(0, 0, ref uEnum);
System.Reflection.MemberInfo inf = typeof(PSTORECLib.CEnumTypes);
GuidAttribute CEnumGuid = 
    (GuidAttribute)inf.GetCustomAttributes(typeof(GuidAttribute), false)[0];
Guid tmp = new Guid(CEnumGuid.Value);
IntPtr ppv;
Marshal.QueryInterface((IntPtr)uEnum, ref tmp, out ppv);
PSTORECLib.CEnumTypes EnumPStoreTypes = 
    (PSTORECLib.CEnumTypes)Marshal.GetObjectForIUnknown(ppv);

//Later
Marshal.Release(ppv);

When I tried stuffing IEnumPStoreTypes** in the idl file of the PSTORECLib (i.e. when I used the initial IDL output by oleview) into the call to PStore.EnumTypes, the dll output by tlbimp told me to pass in a reference to a CEnumTypes. The function was happy with this (it returned S_OK), but it didn’t populate the reference. This mess of ugly code is what happened when I changed it to accept a pointer to a long instead, and is what I did to get an instance of CEnumTypes to refer to the pointer. This whole thing strikes me as being a bit messy, though it does work. Is there a cleaner way to do this?

Note that the line PSTORECLib.CEnumTypes cen = new PSTORECLib.CEnumTypes(); will throw a “Class Not Registered” COMException.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:38:04+00:00Added an answer on May 17, 2026 at 6:38 am

    Ouch, you’re hacking COM the low-level way. It is roughly okay, but there are problems. It will never work in 64-bit mode, uEnum can’t be a uint, it has to be a pointer. It is also being leaked, you don’t call Release() for it. You can’t ignore that.

    Clearly you’ve got a type library and created a interop library from it or else the reflection code wouldn’t work. I can only guess that there’s something wrong with the IDL. The signature of EnumTypes suggests that you forgot the [out,retval] attributes on the last argument. At least post the IDL for EnumTypes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering if there is any cleaner way to write the controller code?
I'm wondering if there is a cleaner way to pass multiple variables in a
I was wondering if there was a more efficient (efficient as in simpler/cleaner code)
Not a major problem but I was wondering if there is a cleaner way
I'm wondering if there's a cleaner and more efficient way of doing the following
Wondering if there is any way to get the lambda expressions that result from
Wondering if there is a good way to generate temporary URLs that expire in
Just wondering if there is an easy way to add the functionality to duplicate
Just wondering if there is any way (in C) to get the contents of
I have a query below that works but was wondering if there is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.