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

  • Home
  • SEARCH
  • 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 6111005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:34:52+00:00 2026-05-23T14:34:52+00:00

I am working with a COM plugin interface that has the following function definition:

  • 0

I am working with a COM plugin interface that has the following function definition:

HRESULT foo ( [out, ref] VARIANT* a, [out, ref] VARIANT* b );

When using tlbimp (tlbimp2.exe from codeplex) the .NET library has the following interface function:

int foo ( out object a, out object b );

The problem is that the calling application will make the function call:

VARIANT a;
::InitVariant( &a );

plugin->foo( &a, NULL );

And in C# I implemented the function:

int foo ( out object a, out object b )
{
    a = 1;
    b = 2;

    return 0; // S_OK
}

When all is said and done the application actually gets a E_POINTER return and not S_OK. I assume it is because of the NULL passed the the out parameter.

Is there a way to check if the address pointer is NULL in the C# implementation?

Note: out parameters are not initialized so you cant use the parameters at all.

I’ve tried implementing the interface as [in, out, ref] to force C# to use ( ref object a, ref object b ) but that did not work either.

Update

Hans is absolutely correct that we should have been calling the function with a NULL ptr if we were declaring it as [out,ref].

erurainon was also correct that we could just use IntPtr to get to the Variant*.

So here is how it was fixed:

int foo ([MarshalAs(UnmanagedType.Struct)]out object a, [MarshalAs(UnmanagedType.Struct)]out object b);

became

int foo ([MarshalAs(UnmanagedType.Struct)]out object a, IntPtr b );

Now we can test for the NULL cases with:

if ( b == IntPtr.Zero )

However since we are dealing with Variant you can’t just copy the value to the IntPtr like:

Marshal.StructureToPtr( myValue, b, false );

So following this post, you need to make a struct class:

[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct PropVariant
{
    [FieldOffset(0)]
    public VarEnum variantType;
    [FieldOffset(8)]
    public IntPtr pointerValue;
    [FieldOffset(8)]
    public byte byteValue;
    [FieldOffset(8)]
    public long longValue;
    [FieldOffset(8)]
    public double dateValue;
    [FieldOffset(8)]
    public short boolValue;
}

And the final function looks like this:

int foo( out object a, IntPtr b )
{
    a = 100;

    if ( b != IntPtr.Zero )
    {
        var time = new PropVariant();
        time.dateTime = DateTime.Now.ToOADate();
        time.variantType = VarEnum.VT_DATE;

        Marshal.StructureToPtr( time, b, false );
    }

    return 0; // S_OK
}

Hope this helps someone else in the future

  • 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-23T14:34:52+00:00Added an answer on May 23, 2026 at 2:34 pm

    Hans is right. Either you disallow your API to be called with NULL parameters, or you implement your C# function with IntPtr arguments and check for IntPtr.Zero.

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

Sidebar

Related Questions

I've been using the timeago plugin (http://timeago.yarp.com/), it has been working fine on my
I have been working on a wrapper for a COM object that can only
I am working on a project in eclipse that when I launch using the
I am using jQuery resizable from interface.eyecon.ro/docs/resizable for a menu on a page that
I'm using the jQuery Cycle plugin (malsup.com/jquery/cycle/) on this page: http://artandculturecenter.org It works as
I am using a jquery tablesorter plugin( http://tablesorter.com/docs/ ) for sorting my tables. This
I am using jQuery Form Plugin http://jquery.malsup.com/form/ to submit my form. Here is the
I can't figure out why is not working a jquery plugin (base64 encode decode)
for this I am using colorbox jQuery plugin http://colorpowered.com/colorbox/ and a form. I am
I'm following the tutorial here: http://docs.jquery.com/Plugins/Authoring I just wanted to create a simple plugin

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.