|
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
|
|
|
|
|
Hi,
Get the Integer from IntPtr and then get HWND from the Integer.
eg:
<br />
hWnd = (HWND)((int)iPtr);<br />
Thanks,
Firoz
|
|
|
|
|
any bode could tell if i have to point and rectangle of window using its hwndle (HWND ) with respect to its desktop window and its parent window ?
how to get using hwnd plz ans i am waiting for ur reply?
r00d0034@yahoo.com
|
|
|
|
|
Hello there,
Please introduce good book for learning VC++ .NET ...
I want to learn about .NET, writing webservers and etc by MC++ managed code ...
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
|
Thanks
With Best Regards
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hi
Can anyone tell me how to execute a activeX control application in .Net framework?
I could compile but it asks me for "which excutable" when i try to run.
Thanks
Yogi
|
|
|
|
|
ydasari wrote:
Can anyone tell me how to execute a activeX control application in .Net framework?
I could compile but it asks me for "which excutable" when i try to run.
You can't execute a control obviously. Add another project(exe) to the solution and make it the default project. In that project use the activex control you are making. Now when you take run, the program would get executed that houses the control.
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Hello there !
Sorry for subject
There isn't WAR
I just want to know what is exactly diffrence between VS .NET Enterprise edition and VS .NET Proffesional edition !
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
|
Hello David
Thanks alot for your help
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|