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 7576473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:55:45+00:00 2026-05-30T16:55:45+00:00

I have an unmanaged library which I want to use from a managed class.

  • 0

I have an unmanaged library which I want to use from a managed class. The interface of the function is:

GetProgress(short* value);

So I wrote in my managed class:

short val = 0;
GetProgress(&val);

I got the following error:

Error C2664: ‘GetProgress’ : cannot convert parameter 1 from ‘cli::interior_ptr’ in ‘short *’ with [ Type=short ]

I read this topic, so I changed my code into:

short val = 0;
pin_ptr<short*> pVal = &val;
GetProgress(pVal);

And in addition to the previous error I get

Error C2440: ‘initialisation’ : cannot convert from ‘short *’ to ‘cli::pin_ptr’ with [ Type=short * ]

How can I fix this?

  • 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-30T16:55:47+00:00Added an answer on May 30, 2026 at 4:55 pm

    That’s an interesting one.

    The following code produces C2664 because val can only be a managed type:

    using namespace System;
    
    void GetProgress(short* value)
    {
        // unmanaged goodness
    }
    
    ref class XYZ : System::Object
    {
        short val;
    
        void foo()
        {
            GetProgress(&val);
        }
    };
    

    but if you declare a local variable first, it all works fine…

    using namespace System;
    
    void GetProgress(short* value)
    {
        // unmanaged goodness
    }
    
    ref class XYZ : System::Object
    {
        short val;
    
        void foo()
        {
            short x;
            GetProgress(&x);
            val = x;
        }
    };
    

    Not exactly the answer you were looking for, but I thought I’d include it since it’s a simple fix.

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

Sidebar

Related Questions

I have a class library which is called through COM from a Third Party
I have an unmanaged C++ library for which I've created a managed C++ wrapper.
I want to use an unmanaged COM library (specifically, Skype4COM) in a managed application
I do some thin wrapper of some scientific library (http://root.cern.ch) from unmanaged to managed
I have an unmanaged dll that contains a function to read a data from
I have an unmanaged COM object, and I would like to call it from
I have an unmanaged dll with a class MyClass in it. Now is there
I have two unmanaged pointers in the form of IntPtr and want to copy
I'm in linker paradise now. I have a C library which only compiles in
Here's the setup: A pure DotNET class library is loaded by an unmanaged desktop

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.