|
Here is a trivial example:
// AspCppCli.h
#pragma once
#using <System.Web.dll>
using namespace System;
using namespace System::Web::UI::WebControls;
namespace AspCppCli {
public ref class CppCliTest
{
public:
void InsertGreeting(TextBox ^% tb)
{
tb->Text = "Hello, World!";
}
};
}
-- modified at 22:10 Wednesday 15th February, 2006
|
|
|
|
|
AH!
#using <System.Web.dll>
That makes a difference!
But! Still my point....why do we have to do that!
Thanks for getting me going!!
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
-- modified at 16:16 Thursday 16th February, 2006
|
|
|
|
|
Actually, I feel just like you about this. This kind of makes C++/CLI a second class citizen of managed code.
|
|
|
|
|
Hi,
I need to implement the multi-threading using C++(Not VC++). What are the options available fot it.
Thanks in advance.
Regards
Mahesh
|
|
|
|
|
|
Actually, I wonder why there is no C++ forum here. If he posts the same question in "Visual C++" forum, people will complain that it is not Visual C++ question. If he posts it in here, people still complain that it is not a Managed C++ forum. Poor C++ programmers...
As to the question, you have to use _beginthreadex and _endthreadex. These functions are in C++ standard library and they know how to free the resources of your threads. Don't use beginthread and endthread because they are obsolete. Neither should you use windows CreateThread and ExitThread because Win32 functions don't know about C++ library and may not be able to free the resources adequately.
As a reference I would recommend Jeffrey Richter "Programming Applications for Microsoft Windows". He talks about multithreading, multiprocessing, memory structure (very interesting things like Address Windowing Extensions), exceptions, and other useful stuff. It may be difficult to find this book though. Amazon does not sell it any more.
|
|
|
|
|
RainbowWyrm wrote: I wonder why there is no C++ forum here
the question is legitimate.
consider the fact though that you are on CodeProject on a web site dedicated to the Microsoft development technologies... (Visual Studio, etc...)
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
Yeah, but sometimes, you got to stay platform-independant while still working in Visual Products (though that kinda limits you to C++).
For starters: I got MS VC++ 2005 Express. I use it to develop a OpenSource-Qt freeware tool.
If I have Qt-questions, I AM gonna ask them in a Qt-Forum, but if I am stuck with VS-Problems or Standard-C++ issues, I'd rather ask on CodeProject.
|
|
|
|
|
Sebastian Schneider wrote: if I am stuck with VS-Problems or Standard-C++ issues, I'd rather ask on CodeProject
yeah... that's what the Visual C++ forum is for...
C++/CLI forum is for managed C++ (you know, thet stufs for the .NET framework....)
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
Hi All,
Can anyone tell me where is the memory allocated for a function?. Consider the following example
class A
{
int a;
int b;
void f1();
};
void main()
{
A obj1;
}
Now, in this case, assume that for variable 'a' the address would be 5000 and for 'b' it would be 5004. These 2 varialbes are present in the stack. Now, where does my function lie. Is it placed in the stack? or somewhere else. How do I find the address of the function and know as where it is placed?
can anyone help me on this.
|
|
|
|
|
The code for functions is in the executable, there isn't a separate copy for each instance of a class.
You can get the address of a function like this:
void (A::*pfn)() = A::f1; // or &A::f1 in newer compilers
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi Mike,
Just as a follow on question, you say that there isn't a separate copy for each instance of the class. From my limited understanding of such things, when you create a new instance the run-time creates a new bit of memory to store the class variables. I thought under this it also creates a new code segment for that object. Am I wrong?
Also if there is only one code segment per class, what happens when you have two threads that access two different objects, surely you would have a confict of accessing the same code at the same time?
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
No, code is not created on the stack. The code is already in the executable.
Multiple threads can run the same code simultaneously, all the CPUs are doing is reading memory and executing the instructions they find. The code itself can do non-thread-safe things, but that's a separate issue.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I am not 100% sure, but I believe that the compiler will create a "structure" in the stack, which contains a, b and pointer to the function. The actual function code is in the "instruction set" section of the executable. In general, the class maps into something like this in the stack:
<this> points to a structure which contains the following entries:
[0] Pointer to the virtual function table
[1] First variable
[2] Second variable
...
[N] Pointer to the first non-virtual function
[N+1] Pointer to the second non-virtual function
...
Pointer to the virtual function table points to the structure of pointers to individual virtual functions.
This binary structure of the class is undocumented because it allows you to access private class members through <this> pointer, thus, violating incapsulation. There is also an issue with data alignment of variables a, b, ... when you try to read variables a, b, etc using pointer <this>. There is no problem if they have the same type, that is the same memory size. Otherwise the alignment freaks out depending on the order of integers, doubles, strings etc in which you declared those in the class. I hope this helps.
|
|
|
|
|
Is C++/CLI faster than C#, or do they both convert to the same intermediate code to be run by the .net framework?
|
|
|
|
|
While all CLI compilers generate MSIL, the C++ compiler generates optimized MSIL in some cases (something that none of the other managed languages do). How effective this will be depends on whether the IL optimizations result in improved JITing.
And you can always speed up specific blocks of code by cheating and using #pragma unmanaged
Regards,
Nish
-- modified at 20:16 Monday 13th February, 2006
|
|
|
|
|
Thanks.
I have been thinking about writing a C++/CLI library for some of the spherical trigonometry functions in my planetarium program to speed it up.
|
|
|
|
|
Hi guys!
I want to learn how to create a windows window (instead of the boring DOS prompt) so I have searched and found code for doing this.
However, I get these error messages:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 200 Borland window.cpp:
Warning W8057 window.cpp 50: Parameter 'hPrevInstance' is never used in function __stdcall Winmain(HINSTANCE__ *,HINSTANCE__ *,char *,int)
Warning W8057 windwo.cpp 50: Parameter 'szCmdLine' is never used in function __stdcall WinMain(HINSTANCE__ *,HINSTANCE__ *,char *,int)
Turbo Incremental Link 5.00 Copyright (c) 1997, 200 Borland
Error: Unresolved external '_main' referenced from C:\BORLAND\BCC55\LIB\COX32.OBJ
The code I found that's supposed to create a windows window is the following:
window.cpp:
#include <windows.h>
#include "Resource.h"
LRESULT CALLBACK WndProc( HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam );
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow )
{
static TCHAR szAppName[] = TEXT( "TestApp" );
WNDCLASSEX wndclass;
HWND hWindow;
MSG msg;
wndclass.cbSize = sizeof( wndclass );
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_APPICON ) );
wndclass.hIconSm = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_APPICON_SM ) );
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
wndclass.hbrBackground = ( HBRUSH ) ( COLOR_WINDOW + 1 );
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if( ! RegisterClassEx( & wndclass ) )
return 0;
hWindow = CreateWindow( szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL );
ShowWindow( hWindow, iCmdShow );
UpdateWindow( hWindow );
while( GetMessage( & msg, NULL, 0, 0 ) )
{
TranslateMessage( & msg );
DispatchMessage( & msg );
}
return ( int ) msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam )
{
HDC hDC;
PAINTSTRUCT ps;
RECT rect;
switch( msg )
{
case WM_PAINT:
hDC = BeginPaint( hWindow, & ps );
GetClientRect( hWindow, & rect );
DrawText( hDC, TEXT( "This is some text, just for fun!" ), -1, & rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
EndPaint( hWindow, & ps );
return 0;
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hWindow, msg, wParam, lParam );
}
Resource.h:
#define IDI_APPICON 1000
#define IDI_APPICON_SM 1001
Recourse.rc:
#include "Resource.h"
IDI_APPICON ICON "path/to/appicon.ico"
IDI_APPICON_SM ICON "path/to/small_appicon.ico"
Can anyone help me with this?
Thanks!
Peter
|
|
|
|
|
I don't use Borland, but it looks like you need to change your entry point from "main" to "WinMain".
In visual studio, it's set under project properties->linker->advanced->entry point
or with the following command line:
/ENTRY:"main"
|
|
|
|
|
I'm working in C++ Builder and I have a round LED image that I would like to use. However Builder does not seem to accept transparent sections of the graphic and so the image appears as though it has white corners. Any thoughts on how I could get this to display as an image with a transparent background? I tried loading the image through imagelist and then set the transparent property to the white section and this worked except that the graphic then did not look like the nice quality that it use to? Any thoughts would be greatfull.
Debs*
|
|
|
|
|
if you are using a TImage just set the Transparent property to true
|
|
|
|
|
When I set TImage Transparent property to true. The part of the image that becomes transparent is not a clean cut and looks very pixelly. I believe I have to use bmp image for this transparent property to work and even with a high quality bmp I can't seem to get it to be clean transparent cut. Any other thoughts?
Deborah
|
|
|
|
|
That's one of the reasons I'm gradually moving from C++Builder to C++/CLI. I couldn't find any free controls (at least for BCB 5) that would give me proper alpha transparency.
|
|
|
|
|
Excuss my ignorance but what is C++/CLI? How are you finding the transition?? Do you have a link to more info on C++/CLI?
|
|
|
|
|
It always amazes me how people will post messages to a forum without even bothering to see which forum they're posting in! (That's a hint: you posted your original message here in the C++/CLI forum.)
I guess people just see the first three letters of the forum's name and don't bother to read the rest (I wish CP had a smiley that was less intense than , but more intense than . Maybe a little guy looking annoyed with a bit of steam coming out of his ears.)
Anyway, now that I've had my rant -- C++/CLI is Microsoft's slightly-modified version of C++ that works with their .NET framework. Here's a good introductory article: http://www.codeproject.com/managedcpp/cppcliintro01.asp[^]
|
|
|
|
|