473,804 Members | 3,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug: passing _com_ptr_t by value using managed extensions!?

Hi all,

I've experienced a problem when passing a smart-pointer (_com_ptr_t)
by value to another function using managed extensions. This only seems
to happen if the object is created via new. Can anyone confirm this
issue?

I wrote a little program that demonstrates this behaviour:

Main.cpp:
=========

#include "stdafx.h"

#import "msado25.tl b" rename_namespac e("ADO") named_guids
rename("EOF", "EndOfFile" )

#include "Test.h"

#using <mscorlib.dll >
using namespace System;
using namespace System::Runtime ::InteropServic es;

int main(int argc, char* argv[])
{
try
{
// CREATE A COM-OBJECT
CoInitialize(NU LL);
ADO::_Connectio nPtr con(ADO::CLSID_ Connection);
con->Open("PROVIDER =SQLOLEDB; SERVER=sqltest1 \\dbserv1;
DATABASE=Netzda ten;Trusted_Con nection=Yes;App =MCDataSourceSe rvice",
"", "", 0);

CTest test;
test.TestMe(con ); // WORKS FINE

CTest *ptest = new CTest();
ptest->TestMe(con); // THIS LINE DESTROYS THE UNDERLYING COM-OBJECT
(con)

// THE NEXT LINE THROWS A
System.NullRefe renceException DUE TO THE FACT THAT THE COM-OBJECT HAS
BEEN DESTROYED
printf("connect ion string = %s\n",
(LPCTSTR)con->GetConnectionS tring());
}

catch (_com_error e)
{
_bstr_t bstrDescription = e.Description() ;
}

catch (Exception *e)
{
System::Console ::WriteLine("\n \nException:");
System::Console ::WriteLine(e->ToString());
}

return 0;
}

Test.h
=======

#ifndef _Test
#define _Test

#import "msado25.tl b" rename_namespac e("ADO") named_guids
rename("EOF", "EndOfFile" )

class CTest
{
public:
virtual void TestMe(ADO::_Co nnectionPtr con);
};

Test.cpp
========

#include "stdafx.h"
#include "Test.h"

void CTest::TestMe(A DO::_Connection Ptr con)
{
printf("by value = smart-ptr-address %x\n", con.GetInterfac ePtr());
printf("connect ion string = %s\n",
(LPCTSTR)con->GetConnectionS tring());
}
Nov 17 '05 #1
0 1239

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

Similar topics

1
2979
by: Bruise | last post by:
in VC6-SP5 with ProcessPack, \Include\comip.h, there's a serious bug might cause overwrite: HRESULT CreateInstance(LPCSTR clsidStringA, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw() e.g, when we write code calling ADO like pRstEmployee.CreateInstance("ADODB.Recordset")); pRstEmployee->Open(....
4
13627
by: Jonathan Fielder | last post by:
Hi, My program (below) casts a double (which is in range for a float) to a float. As far as I know this should give me the nearest representable float, which will loose some precision. I then test for a NAN by comparing my float to itself (is this correct?), and I get different behaviour with different compilers. Have I done something that is undefined, or is this a compiler bug? Thanks,
0
974
by: Daniel G?rsch | last post by:
The following code works perfect in VS 2002 (compiled in a console project). Using VS 2003 the variable 'a' in the 'compute' function of the managed class 'M' is not correctly passed into this function. Actually using the debugger shows that the copy constructor of class 'A' is called correctly, but nevertheless the variable 'a' in the 'compute' function is not initilized, that is 'a.i' has random values. Additionally starting the...
35
2184
by: Maxim Yegorushkin | last post by:
The following code: #include <iostream> class base { private: virtual ~base() { std::cout << "virtual ~base()\n";
3
1779
by: Wild Wind | last post by:
Hello, I made a post relating to this issue a while back, but I haven't received any answer, so here I am again. I am writing a mixed C++ dll which uses the following declaration: typedef System::Byte ByteArray __gc;
1
1174
by: Marty | last post by:
Hi, I'm still playing with this managed/unmanaged code within my VC++ project. I'm sure it's gonna work, need just some tuning that you could help me to find out. Here is below the .h and .cpp I use. socketListener.cpp configuration properties: c/c++ - General : /clr
17
3687
by: mr.resistor | last post by:
hey i am having a few problems calling a C DLL from C#. i am using a simple function that takes an array of floats and an integer as an input, but i cannot seem to get it to work. when i try to compile i get the following error: Attempted to read or write protected memory the C function should not be manipulating the input arra, only reading
3
7528
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going on. It's a simple program that loads a control onto a form and binds "Foo" against a combobox ("SelectedItem") for it's "Bar" property and a datetimepicker ("Value") for it's "DateTime" property. The DateTimePicker.Visible value is set to...
4
1505
by: PLS | last post by:
This problem is entirely in Microsoft's VS2005 C++ headers, so I'm hoping someone has hit it before and knows the fix. I am convertied a medium size (400k lines) C++ program over to VS2005 native C++, rewriting it's COM stuff to ATL. I have crtdbg.h in the global include file and have _CRT_MAP_ALLOC turned on at the project level. I'm getting a crash at line 707 in the function _com_ptr_t::CreateInstance in file comip.h. The crash was...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9577
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10569
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10315
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2990
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.