473,769 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Interop - Getting String value back from ATL COM Server

I have a C++/CLI app that uses a logging control in an ATL COM Server. C++
Interop seems to work just fine to pass data from the C++/CLI app to the ATL
Control but I can't seem to figure out how to get a string value back from
the ATL Control. When debugging the code seen below, I see that the VARIANT
pointed to by 'data' is updated but the String 'str' passed from the C++/CLI
app doesn't change. So the String 'str' seems to be passed by value rather
than reference but I can't seem to get anything else to work without throwing
out C++ interop. Any suggestions?
System::Void button2_Click(S ystem::Object^ sender, System::EventAr gs^ e)
{
System::String^ str("temp");

this->axLogCtl1->GetLogText(str );
richTextBox1->Text = str;
}
HRESULT LogCtl::GetLogT ext(VARIANT* data)
{
CComVariant v(m_strData);

/////////////////////////////////////////////////////////////////
// Pass the current log data to the caller.
/////////////////////////////////////////////////////////////////
if (VT_BSTR == data.vt)
v.CopyTo(&(data .bstrVal));

return (S_OK);
}
--

Paul - Consultant: C++ Application Design and Development
May 1 '07 #1
3 2677
Oops... Example should be as follows:

HRESULT LogCtl::GetLogT ext(VARIANT* data)
{
CComVariant v(m_strData);

/////////////////////////////////////////////////////////////////
// Pass the current log data to the caller.
/////////////////////////////////////////////////////////////////
if (VT_BSTR == data->vt)
v.CopyTo(&(data->bstrVal));

return (S_OK);
}

--
Consultant: C++ Application Design and Development
"spd3001" wrote:
I have a C++/CLI app that uses a logging control in an ATL COM Server. C++
Interop seems to work just fine to pass data from the C++/CLI app to the ATL
Control but I can't seem to figure out how to get a string value back from
the ATL Control. When debugging the code seen below, I see that the VARIANT
pointed to by 'data' is updated but the String 'str' passed from the C++/CLI
app doesn't change. So the String 'str' seems to be passed by value rather
than reference but I can't seem to get anything else to work without throwing
out C++ interop. Any suggestions?
System::Void button2_Click(S ystem::Object^ sender, System::EventAr gs^ e)
{
System::String^ str("temp");

this->axLogCtl1->GetLogText(str );
richTextBox1->Text = str;
}
HRESULT LogCtl::GetLogT ext(VARIANT* data)
{
CComVariant v(m_strData);

/////////////////////////////////////////////////////////////////
// Pass the current log data to the caller.
/////////////////////////////////////////////////////////////////
if (VT_BSTR == data.vt)
v.CopyTo(&(data .bstrVal));

return (S_OK);
}
--

Paul - Consultant: C++ Application Design and Development
May 1 '07 #2
How is the axLogCtl1->GetLogText() method defined in C++/CLI?

If you want the value back, you should define the parameter as an out or ref

---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExte nsions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensio ns.Net : Develop all shell extensions,expl orer bars and BHOs
rapidly in .Net
---------

"spd3001" <sp*****@discus sions.microsoft .comwrote in message
news:FA******** *************** ***********@mic rosoft.com...
>I have a C++/CLI app that uses a logging control in an ATL COM Server. C++
Interop seems to work just fine to pass data from the C++/CLI app to the
ATL
Control but I can't seem to figure out how to get a string value back from
the ATL Control. When debugging the code seen below, I see that the
VARIANT
pointed to by 'data' is updated but the String 'str' passed from the
C++/CLI
app doesn't change. So the String 'str' seems to be passed by value
rather
than reference but I can't seem to get anything else to work without
throwing
out C++ interop. Any suggestions?
System::Void button2_Click(S ystem::Object^ sender, System::EventAr gs^ e)
{
System::String^ str("temp");

this->axLogCtl1->GetLogText(str );
richTextBox1->Text = str;
}
HRESULT LogCtl::GetLogT ext(VARIANT* data)
{
CComVariant v(m_strData);

/////////////////////////////////////////////////////////////////
// Pass the current log data to the caller.
/////////////////////////////////////////////////////////////////
if (VT_BSTR == data.vt)
v.CopyTo(&(data .bstrVal));

return (S_OK);
}
--

Paul - Consultant: C++ Application Design and Development

May 2 '07 #3
Finally got it to work as follows:

System::Void toolStripButton 1_Click(System: :Object^ sender,
System::EventAr gs^ e)
{
IntPtr ip = Marshal::AllocH Global(0x00007F FF);
void * p = ip.ToPointer();
BYTE * pStr = (BYTE *) p;

this->axLogCtl1->GetLogText(*pS tr);
richTextBox1->Text = Marshal::PtrToS tringAuto(ip);

Marshal::FreeHG lobal(ip);

}

HRESULT LogCtl::GetLogT ext(BYTE * data)
{
_tcscpy_s((TCHA R *) data,
0x00007FFF/sizeof(TCHAR),
(const TCHAR *)m_strData.Get Buffer());

return (S_OK);
}

--
Consultant: C++ Application Design and Development
"G Himangi" wrote:
How is the axLogCtl1->GetLogText() method defined in C++/CLI?

If you want the value back, you should define the parameter as an out or ref

---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExte nsions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensio ns.Net : Develop all shell extensions,expl orer bars and BHOs
rapidly in .Net
---------

"spd3001" <sp*****@discus sions.microsoft .comwrote in message
news:FA******** *************** ***********@mic rosoft.com...
I have a C++/CLI app that uses a logging control in an ATL COM Server. C++
Interop seems to work just fine to pass data from the C++/CLI app to the
ATL
Control but I can't seem to figure out how to get a string value back from
the ATL Control. When debugging the code seen below, I see that the
VARIANT
pointed to by 'data' is updated but the String 'str' passed from the
C++/CLI
app doesn't change. So the String 'str' seems to be passed by value
rather
than reference but I can't seem to get anything else to work without
throwing
out C++ interop. Any suggestions?
System::Void button2_Click(S ystem::Object^ sender, System::EventAr gs^ e)
{
System::String^ str("temp");

this->axLogCtl1->GetLogText(str );
richTextBox1->Text = str;
}
HRESULT LogCtl::GetLogT ext(VARIANT* data)
{
CComVariant v(m_strData);

/////////////////////////////////////////////////////////////////
// Pass the current log data to the caller.
/////////////////////////////////////////////////////////////////
if (VT_BSTR == data.vt)
v.CopyTo(&(data .bstrVal));

return (S_OK);
}
--

Paul - Consultant: C++ Application Design and Development


May 2 '07 #4

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

Similar topics

1
1998
by: Nadav | last post by:
Hi, Introduction *************** I have a system build of a collection of 'Native COM objects' and '.NET COM interop' objects, all of the COM objects are managed through a 'Native COM' layer, this layer manage the underlying COM Objects and upon request, provide a pointer to those objects to the 'API Consumer', following is an illustration of the system: API Consumer ( Native C++/C# ) || ******************************************* * ...
20
3198
by: Razzie | last post by:
Hey all, I'm really going through a small hell right now - I've completely lost it :) I made a project, using two interop libraries from exchange (created them as in this msdn article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsmtps/html/writingmngsinks.asp). I set my project properties as 'Register as COM interop' to true, I can install it my project on my developement machine without a flaw. Great.
22
4846
by: glenn | last post by:
I have a COM Server that I've written based on information from the book ..NET and COM / the complete Interop Guide. I have gotten the project to compile and I've located the regasm.exe program that I was suppose to run against my dll in order to generate a TLB file for the purposes of importing the COM object into other programming lanugages such as Delphi. However, when I try to import the type library into Delphi which I have done...
3
2521
by: Jeffery Franzen | last post by:
Anyone know where the documentation is regarding Activex controls in asp web forms? I'm using VS.NET 2002 enterprise and am trying to use Activex controls in vb.net web form app. I do the add control to pallete and then add a reference. I get the interop dll added to bin folder. I did this with the MediaPlayer activex control as a simple case to to try and get it working. I set the control to autostart via the html parameter tag for...
10
1945
by: Peter Afonin | last post by:
Hello, I have a simple client-side form that is checking the domain availability on the domain registrar's server: <FORM action="https://www.webnames.ru/scripts/RegTimeSRS.pl" method="post"> <input type="hidden" name="thisPage" value="pispCheckDomain"> <input type="hidden" name="username" value="test"> <input type="hidden" name="password" value="test"> domain_name: <input type="text" name="domain_name"><br>
5
5991
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an event is fired by one of the controls contained in the User Control, these variable are reset. Here is my current code (I have a little more to add later, right now I am just concerned about the variables getting reset): Public Class DatePicker2...
0
2131
by: kagorami | last post by:
Q: How do you return a LPSTR from unmanaged code? A: Use a StringBuilder. What about this: public struct CSTRUCT { string return_value; } How do you get a LPSTR from unmanaged code when it is in a STRUCT?
7
10962
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed this screen below. Please help, thanks in advance... Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify...
3
11652
OuTCasT
by: OuTCasT | last post by:
Hi I have created an asp.net project that exports items from datagridview to and outlook calendar This is the code that i have used.. Dim body As String Dim ends As String Dim location As String Dim start As String Dim subject As String
0
9590
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
9424
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
10223
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
10051
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...
0
9866
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...
0
8879
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
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 we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.