|
I have a dll where i write
// RMLib1.h
#pragma once
#using <mscorlib.dll>
#using <system.runtime.remoting.dll>
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
namespace RMLib1
{
public __gc class HelloObj:public MarshalByRefObject
{
public:
HelloObj();
String* Greet(String* name);
private:
int numGreet;
};
}
#include "stdafx.h"
this is implementation of these methods
#include "RMLib1.h"
using namespace RMLib1;
HelloObj::HelloObj()
{
Console::WriteLine("HelloObj Activated ");
}
String* HelloObj::Greet(String* name)
{
numGreet++;
String* greeting =S"Hello" ;
return greeting;
}
Inother project i try register this objas remote services
using namespace System;
#using <system.runtime.remoting.dll>
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
#using <rmlib1.dll>
using namespace RMLib1;
// This is the entry point for this application
int _tmain(void)
{
Console::WriteLine(S"Hello World");
TcpChannel* chan = new TcpChannel(8085);
ChannelServices::RegisterChannel(chan);
Console::WriteLine(S"Registering Hello Obj As SingleTon ");
RemotingConfiguration::RegisterWellKnownServiceType(Type::GetType("HelloObj"),"HelloObj",WellKnownObjectMode::Singleton);
Console::WriteLine(S"Waiting For Remote Calls");
Console::WriteLine(S"Hit Enter To Exit ");
Console::ReadLine();
return 0;
}
I can compile this code but when try to excecute it gives me
error
System.ArgumentNullException:Value Can not be Be NULL Parameter Name:Type
This line is giving Problem Any Idea.............
RemotingConfiguration::RegisterWellKnownServiceType(Type::GetType("HelloObj"),"HelloObj",WellKnownObjectMode::Singleton);
|
|
|
|
|
Hi
I am new VC++ Can AnyOne Give Me Remoting Example in VC++
using DOTNET
Not in C# or VB>Net
pure VC++
I ll be than ful to u
Harvail
|
|
|
|
|
|
how to use DECLARE_MESSAGE_MAP()in a managed class ?
r00d0034@yahoo.com
|
|
|
|
|
Folks,
I was wondering if there is a way to convert String(managed type) to Cstring(unmanaged type) in MC++?
Appreciate your comments/replies.
CHEERS
John
|
|
|
|
|
#include <vcclr.h>
then, call PtrToStringChars(), passing the managed string:
String* fx_string = S"Hello, World";
CString mfc_string = PtrToStringChars(fx_string);
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
|
I had to check to see why this works because it shouldn't - unless there exists a constructor for CString that takes a String*.
And there is. CString has a constructor that looks like this - note it does exactly what I prescribed (and pins the pointer, which I think I neglected to do):
CStringT( System::String* pString ) :
CThisSimpleString( StringTraits::GetDefaultManager() )
{
const wchar_t __pin* psz = PtrToStringChars( pString );
*this = psz;
}
good catch.
N
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Nick Hodapp (MSFT) wrote:
good catch.
Yeah, I was using this when comparing a String* to a CString in my N-Track program (MFC/MC++ mix). But I just realized that, that is inefficient, because each time a CString object was being allocated on the stack
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Nick,
I had a similar problem, this time involving a CString array.
I have found the source of the problem expressed in the thread "ADO.NET : SqlDataReader : I need to assign retrieved value to C++ variable":
http://www.codeproject.com/script/comments/forums.asp?forumid=3785#xx309754xx
but do not yet know why it occurs or how I can fix it.
The problem arises with the /clr compiler setting.
Here is the code to illustrate this:
/////////////////////////////////////////////////////////
#include <stdafx.h>
#include <cstdlib>
#include "try_ADONET.h"
//#using <mscorlib.dll>
//#using <system.dll>
//#using <system.data.dll> // This is required for the ADO.NET Provider
using namespace std;
//using namespace System;
int Main()
{
CString busNumberSQL[2];
CString bus = "Hello";
busNumberSQL[1] = bus;
return 0;
}
////////////////////////////////////////////////////////
Without the /clr setting the array of CString busNumberSQL[2] is correctly contructed as is CString bus and the line
busNumberSQL[1] = bus;
works as expected. This can be seen by putting a breakpoint in at
return 0;
and seeing the variables in a Watch. Copy the expanded Watch details (Name, Value & Type) to an EXCEL sheet.
..................
Next, add the compiler switch /clr and rerun the code.
CString bus is constructed correctly BUT something weird happens in the construction of CString busNumberSQL[2].
Now,
busNumberSQL[1] = bus;
results in the address of bus as an integer being assigned to busNumberSQL[1], and look at the Watch details!!
Copy the expanded Watch details (Name, Value & Type) to an EXCEL sheet
Name: busNumberSQL; Value: {Length=2}; Type: ATL::CStringT<char,strtraitmfc<char,atl::chtraitscrt<char> > >[] ...(Note no dimension at end compared to the "no /clr" case.
Next Watch line: [0] 2083454756 __int32
Next Watch line: [1] 3103464 __int32
My conclusion is that busNumberSQL[2] is not an array of CString.
Of course, I need the /clr in order to use ADO.NET!
It seems as though a CString works, but a CString array for some (unknown) cannot even be defined.
Do you have any light for me? (I have not got into your previous post yet on Marshall)
Best regards
Doug.
(In case you are wondering I am very much a beginner with C++ and .NET)
Doug
|
|
|
|
|
I am going thru some code conversion and having bad time with MC++.
Can anyyou help me with this?
There is an activeX control which is to be converted for .net.
__gc class Rinex{
}
class CRinex_ControlCtrl : public COleControl
{
Rinex *x; // This is an error as CRinex_controlctl is unmanaged class.
}
I thought all comp generated classes are managed. But if i make it managed with __gc, all the code (comp generated) has to be changed. Do you know how to avert this problem?
One other problem is converting from a variable from char [] to string? How do you convert? There is a sample code below.
char x __gc[];
x[]=new x __gc[10];
int i= strlen(x); // This gives an error.
Even a type-cast does not work.Thanks for you help.
|
|
|
|
|
If you want to contain an instance of a managed object inside an unmanaged class (per your example) you need to use gcroot<>. gcroot is a template class (#include either vcclr.h or gcroot.h) that wraps the functionality of GCHandle. GCHandle is a .NET Framework class that tells the garbage collecter there is an instance of a class pointed to by memory outside its control (likely the C++ heap, in this example).
__gc class Rinex
{
};
class CRinex_ControlCtrl
{
gcroot<Rinex*> x;
};
When you compile with /clr the compiler will generate all code as MSIL, but no datatypes are magically made into managed types.
When you pass managed data to an unmanaged function (as you are attempting to do with your strlen() problem), you must first pin the data so that the garbage collector doesn't move it during the call:
char x __gc[];
x = new char __gc[10];
char __pin* pinned_x = &x[0];
int i= strlen(pinned_x);
You can read more about pinning in an article I wrote, here.
Cheers,
Nick
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
But Isn't it true that all the default classes in MFC (I mean, the computer generated classes) are managed.
If not, how does garbage collection occur for such classes?
Thanks
Yogi
|
|
|
|
|
No; MFC classes are not garbage collected. Depending on the usage, MFC has built in behavior to manage the lifetime of some classes, e.g. views, using standard C++ technique (new/delete).
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
please tell how to remove this error ?
when i exceute these lines
Process tmpProcess;
..
IntPtr hWnd=tmpProcess->Handle;
System::IntPtr::op_Explicit(hWnd);
//*****************************************************
last line recive following error plz tell how to remove this ambiguity ?
//***********************************
errorr is that
send_recive_messages.cpp(48) : error C2668: 'System::IntPtr::op_Explicit' : ambiguous call to overloaded function
d:\final project\Copy (3) of Windows_processes_hwnd\hwnd_managment\Stdafx.h(7): could be '__int64 System::IntPtr::op_Explicit(System::IntPtr)'
d:\final project\Copy (3) of Windows_processes_hwnd\hwnd_managment\Stdafx.h(7): or 'int System::IntPtr::op_Explicit(System::IntPtr)'
d:\final project\Copy (3) of Windows_processes_hwnd\hwnd_managment\Stdafx.h(7): or 'void *System::IntPtr::op_Explicit(System::IntPtr)'
r00d0034@yahoo.com
|
|
|
|
|
First of all, your variable naming implies that you are expecting tmpProcess->Handle to be a window handle. It is not; it is a process handle. Also, in C++, since Process is a reference type, it must be declared as a pointer:
System::Diagnostics::Process* tmpProcess;
The op_Explicit() operator you are calling exists for implicit casting purposes in C# -- convert the value held by the IntPtr to an __int64, int, or void*. (Recall that the native size of the value of an IntPtr is determined by the platform; on 32bit hardware it is 32 bits, would be 64bits on 64bit hardware).
I'll ask around, but I think in C++ it is impossible to disambiguate this function-call because in C++ it is illegal to overload a function based soely on its return type, which is what is happening here.
You can get the same functionality by calling one of the conversion members: IntPtr::ToInt32(), IntPtr::ToInt64(), or IntPtr::ToPointer():
long l = hWnd->ToInt32();
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
who to communicate with a process.lets say there are a number of components on its main window how to pass messages to them,who to passs data to their edit boxes and text areas.
who to get its mainwindow hawndle i tried to get its hwndle like that
Process tmpProcess;
..
tmpProcess.start();
tmpProcess.WaitForInputIdle();
IntPtr hWnd=tmpProcess.MainWindowHandle;
HWND t_hwnd=(HWND)hWnd.ToInt32();
but thats not its main window handle because when i get its rectangle its points are not correct.
what to do if i want to have processes mainwindow hwnd?
i also want to get process main window new handle when its window changes after some processing how to get it?
is there any other way to communicate with process ?
plz provide the helping metrial and related links for that?
i will be very thank full to u.
|
|
|
|
|
Grrr... I have done so much bitmap work that I feel embarassed even asking this!
But I'm stuck!
I create a ddb on a 32 bits per pixel display. Now I want to save this as a 24 bit bitmap --- rather than a 32 bit bitmap (which I can do just fine).
I'm using the dib api functions provided by microsoft (slighty modified), namely this function:
<br />
HDIB WINAPI CreateDibFromBitmap(HBITMAP hBitmap, HPALETTE hPal, <br />
int bitsPerPixel)<br />
{<br />
HDIB hDIB = NULL;<br />
<br />
BITMAP bm;
BITMAPINFOHEADER bi;
BITMAPINFOHEADER FAR *lpbi = NULL;
DWORD dwLen = 0;
HDIB h = NULL;
HDC hDC = NULL;
WORD biBits = 0;
<br />
<br />
<br />
if (!hBitmap)<br />
return NULL;<br />
<br />
<br />
if (!GetObject(hBitmap, sizeof(bm), (LPSTR)&bm))<br />
return NULL;<br />
<br />
<br />
if (hPal == NULL)<br />
hPal = (HPALETTE)::GetStockObject(DEFAULT_PALETTE);<br />
<br />
if(bitsPerPixel == 0)<br />
{<br />
<br />
biBits = bm.bmPlanes * bm.bmBitsPixel;<br />
}<br />
else<br />
{<br />
biBits = bitsPerPixel;<br />
}<br />
<br />
<br />
if (biBits <= 1)<br />
biBits = 1;<br />
else if (biBits <= 4)<br />
biBits = 4;<br />
else if (biBits <= 8)<br />
biBits = 8;<br />
else <br />
biBits = 24;<br />
<br />
<br />
bi.biSize = sizeof(BITMAPINFOHEADER);<br />
bi.biWidth = bm.bmWidth;<br />
bi.biHeight = bm.bmHeight;<br />
bi.biPlanes = 1;<br />
bi.biBitCount = biBits;<br />
bi.biCompression = BI_RGB;<br />
bi.biSizeImage = 0;<br />
bi.biXPelsPerMeter = 0;<br />
bi.biYPelsPerMeter = 0;<br />
bi.biClrUsed = 0;<br />
bi.biClrImportant = 0;<br />
<br />
<br />
dwLen = bi.biSize + PaletteSize((LPSTR)&bi);<br />
<br />
<br />
hDC = GetDC(NULL);<br />
<br />
<br />
hPal = SelectPalette(hDC, hPal, FALSE);<br />
RealizePalette(hDC);<br />
<br />
<br />
hDIB = (HDIB)GlobalAlloc(GHND, dwLen);<br />
<br />
<br />
if (!hDIB)<br />
{<br />
<br />
SelectPalette(hDC, hPal, TRUE);<br />
RealizePalette(hDC);<br />
ReleaseDC(NULL, hDC);<br />
return NULL;<br />
}<br />
<br />
<br />
lpbi = (BITMAPINFOHEADER*)GlobalLock(hDIB);<br />
<br />
<br />
*lpbi = bi;<br />
<br />
<br />
GetDIBits(hDC, hBitmap, 0, (WORD)bi.biHeight, NULL, (LPBITMAPINFO)lpbi,<br />
DIB_RGB_COLORS);<br />
<br />
<br />
bi = *lpbi;<br />
GlobalUnlock(hDIB);<br />
<br />
<br />
if (bi.biSizeImage == 0)<br />
bi.biSizeImage = WIDTHBYTES((DWORD)bm.bmWidth * biBits) * bm.bmHeight;<br />
<br />
<br />
dwLen = bi.biSize + PaletteSize((LPSTR)&bi) + bi.biSizeImage;<br />
if (h = (HDIB)GlobalReAlloc(hDIB, dwLen, 0))<br />
hDIB = h;<br />
else<br />
{<br />
<br />
GlobalFree(hDIB);<br />
hDIB = NULL;<br />
SelectPalette(hDC, hPal, TRUE);<br />
RealizePalette(hDC);<br />
ReleaseDC(NULL, hDC);<br />
return NULL;<br />
}<br />
<br />
<br />
lpbi = (BITMAPINFOHEADER*)GlobalLock(hDIB);<br />
<br />
<br />
int result = GetDIBits(hDC, hBitmap, 0, (WORD)bi.biHeight,<br />
(LPSTR)lpbi + (WORD)lpbi->biSize + PaletteSize((LPSTR)lpbi), <br />
(LPBITMAPINFO)lpbi, DIB_RGB_COLORS);<br />
<br />
if(result == 0)<br />
{<br />
<br />
GlobalUnlock(hDIB);<br />
hDIB = NULL;<br />
SelectPalette(hDC, hPal, TRUE);<br />
RealizePalette(hDC);<br />
ReleaseDC(NULL, hDC);<br />
return NULL;<br />
}<br />
bi = *lpbi;<br />
<br />
<br />
GlobalUnlock(hDIB);<br />
SelectPalette(hDC, hPal, TRUE);<br />
RealizePalette(hDC);<br />
ReleaseDC(NULL, hDC);<br />
<br />
<br />
return hDIB;<br />
} <br />
I pass in the bitmap handle, NULL for the palette, and then 24 for the bitsPerPixel. But the second call to GetDIBits() fails with a return result of 0.
Does anyone know why?
Thanks for your time.
Cheers,
swine
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
How can i use the mouseDown event to have a label follow the mouse until the mouseUp event?
|
|
|
|
|
HI
I am looking for Remoting Example in VC++
But not finding anywhere on Net .Everywhere it is C#
But happened to C++ Programmer
Can any one tell me How to write Server and Client
in VC++ (Remoting of Dot Net) Or Where i can find a good article
Thnx
Harvail
|
|
|
|
|
i have a form and a button on it in csharp(pro 1) and i also add a managed lib progect(pro 2) to it.I creat dialog box in managed project and i want when a botton on form in csharp is clicked that dialog box should appear.
is it possible ?
because when i execute that code in managed class
dlg_class *ptr;
ptr=new dlg_class();
ptr->DoModal();
An error occure at above last line and that is
D:\Program Files\Microsoft Visual Studio .NET\Vc7\atlmfc\include\afxv_w32.h(18) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
Can any body tell how to over come it.i will be very thank full to u.
r00d0034@yahoo.com
|
|
|
|
|
__gc struct hello{
int x;
int y;
};
void main()
{
hello* st[]= new hello* [5];
st[0]->x=199;
}
|
|
|
|
|
You have simply created an array. But you haven't created the individual array members yet! Use the following code :-
__gc struct hello
{
int x;
int y;
};
int _tmain(void)
{
hello *st[]= new hello*[5];
for(int i=0; i<5; i++)
st[i] = new hello();
st[0]->x = 100;
return 0;
}
Regards,
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
please provide the link of different comprehancive examples of com and com+
and a little help how to run it?
r00d0034@yahoo.com
|
|
|
|
|
if i have hwndle (Intptr)of parent window and hwndle of child window then how to get the point and rectangle of child window with respect to its parent window ?
how to convert HWND into intptr?
r00d0034@yahoo.com
|
|
|
|