473,503 Members | 3,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot convert parameter from cli::interior_ptr<Type>

I've just started using managed C++ with VS2005, so please forgive my
ignorance.
I'm investigating producing a managed wrapper for some functionality of the
Windows Media Format SDK.

I have the following very simple header and class files:

Header File:
// CSJ.h

#pragma once

using namespace System;

namespace CSJ {

public ref class Class1
{
private:
IWMReader* m_pReader;

public:
void Init();
};
}

Class File:
// This is the main DLL file.

#include "stdafx.h"
#include <vcclr.h>
#include <wmsdk.h>
#include <asferr.h>
#include <nserror.h>

#include "CSJ.h"

void CSJ::Class1::Init()
{
HRESULT hr;

hr = WMCreateReader(NULL, WMT_RIGHT_PLAYBACK, &m_pReader);
}

This results in a compilation error C2664: 'WMCreatereader' : cannot convert
parameter 3 from 'cli::interior_ptr<Type>' to 'IWMReader **'

If I move the declaration of m_pReader into the Init() function everything
compiles, but I need m_pReader as a class level variable. How do I correctly
declare m_pReader ?

Any help would be appreciated.

Thanks

Steve

Jan 12 '06 #1
2 10928
"Steve Wilkinson" <St************@discussions.microsoft.com> wrote
void CSJ::Class1::Init()
{
HRESULT hr;

hr = WMCreateReader(NULL, WMT_RIGHT_PLAYBACK, &m_pReader);
}

This results in a compilation error C2664: 'WMCreatereader' : cannot
convert
parameter 3 from 'cli::interior_ptr<Type>' to 'IWMReader **'
interior_ptr is a managed pointer. Managed pointers are reported to the GC.
If you want to call into unmanaged code you need to tell the execution
engine
that the pointee should not be moved and hence the pointer value doesn't
change.

To do so, you need a managed pointer with the pinned attribute to point
to the object. The corresponding C++/CLI construction is pin_ptr.

Try
pin_ptr<IWMReader*> p = &m_pReader;
WMCreateReader(....p);

pin_ptr implicitly converts to a native pointer which is valid so long as
the object is pinned (typically until p is assigned another value or goes
out of scope)
If I move the declaration of m_pReader into the Init() function everything
compiles, but I need m_pReader as a class level variable. How do I
correctly
declare m_pReader ?

That's because it resides on the stack. Items on the stack are never moved
by the GC. It is safe to assume that pointer is stable during the execution
of
the function.

-hg
Jan 12 '06 #2
Thanks Holger, that did the trick.

"Holger Grund" wrote:
"Steve Wilkinson" <St************@discussions.microsoft.com> wrote
void CSJ::Class1::Init()
{
HRESULT hr;

hr = WMCreateReader(NULL, WMT_RIGHT_PLAYBACK, &m_pReader);
}

This results in a compilation error C2664: 'WMCreatereader' : cannot
convert
parameter 3 from 'cli::interior_ptr<Type>' to 'IWMReader **'

interior_ptr is a managed pointer. Managed pointers are reported to the GC.
If you want to call into unmanaged code you need to tell the execution
engine
that the pointee should not be moved and hence the pointer value doesn't
change.

To do so, you need a managed pointer with the pinned attribute to point
to the object. The corresponding C++/CLI construction is pin_ptr.

Try
pin_ptr<IWMReader*> p = &m_pReader;
WMCreateReader(....p);

pin_ptr implicitly converts to a native pointer which is valid so long as
the object is pinned (typically until p is assigned another value or goes
out of scope)
If I move the declaration of m_pReader into the Init() function everything
compiles, but I need m_pReader as a class level variable. How do I
correctly
declare m_pReader ?

That's because it resides on the stack. Items on the stack are never moved
by the GC. It is safe to assume that pointer is stable during the execution
of
the function.

-hg

Jan 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
6234
by: =?Utf-8?B?V2hpdG5leSBLZXc=?= | last post by:
Hi there, I'm having a bit of trouble using an HRASCONN object as a class member variable inside my managed C++ class. When I call RasDial() and pass in the address of my HRASCONN object, I get...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.