|
Easier to use, better library support, more support online, I'd say it's a more likely choice for someone starting to program windows.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I know I was entertained by the response after the original post.
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Hi,
I'm running a team where our .net development is going to need to integrate with some commercial software with C++ APIs. I've identified Managed C++ as the implementation mechanism for integrating the technologies and we have a couple of prototypes working...
.. however, I've managed to convince the Project Manager that we should have a couple of reference books available for the team.
Can anyone recommend any MC++ books, specifically Visual Studio 2005?
Regards,
Ray
|
|
|
|
|
Ray,
Unfortunately, there aren't many books available. However, I have found the following useful:
C++/CLI
The Visual C++ Language for .NET
Gordon Hogenson, Apress
ISBN-13:978-1-59059-705-7
ISBN-10:59059-705-2
This deals mostly with the C++/CLI language. The same author will have the following available in April, 2007:
Expert Visual C++/CLI, Apress
Also,
Pro Visual C++/CLI and the .NET 2.0 Platform
Stephen G. Fraser. Apress
seems to be more for beginners than the aforementioned.
Also,
C++/CLI in Action
Nishant Sivakumar, Manning
ISBN: 1-932394-81-8
will be released in April, 2007 also. This book is written by one of our great contributors here at the Code Project.
Geo.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi,
I have a question regarding C++/CLI and classes. I can declare a managed class like this:
#pragma managed<br />
public ref class A<br />
{<br />
public:<br />
void DoSomething();<br />
};
The compiler will translate this one into MSIL or CIL. And I can use this class in any .Net language by adding my compiled dll/exe as a reference e.g. in a C# project.
And here's the unmanaged pendant:
#pragma unmanaged<br />
class B<br />
{<br />
public:<br />
void DoSomething();<br />
};
This is code gets translated into native code.
But what happens, if I have the following:
#pragma managed<br />
class C<br />
{<br />
public:<br />
void DoSomething();<br />
};
What does the compiler exactly with this code? I'm confused
|
|
|
|
|
class C gets compiled to MSIL. Check it out in the disassembler
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Hi Marc, thank you for the information. Well, I used Reflector.Net and didn't see these "hyrid" classes. But how is it possible that e.g. the managed class C could inherit from native class B?
And if I call call a native function in class C, does it use internally PInvoke to call it? So, is it basically faster to call managed functions/methods from class C than calling native functions?
|
|
|
|
|
class C is not a managed class. It is compiled to MSIL because of the #pragma managed (or by
default if no #pragma used and the /CLR compiler switch is used) but that doesn't make it a
managed class.
I'm not sure about the specifics of how native calls get done from MSIL but I don't think it
involves pinvoke since it's not a managed class.
Ludi83 wrote: So, is it basically faster to call managed functions/methods from class C than calling native functions?
Whether you compile your unmanaged classes to MSIL or native, all the same rules apply when mixing
managed and unmanaged classes. Intuitively, any MSIL code should be slightly slower than native
C++ code but since it's JIT compiled (not interpreted) there's no noticable difference in speed
that I've seen. I've never benchmarked it but I bet the difference is minimal.
If performance is an issue, marshalling between managed and unmanaged code is a way bigger issue
than how the unmanaged code is compiled.
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
I have a .NET project with a mix of standart interop in C# and Managed C++.
It used to work and compile fine on WindowsXP 32 bits, with Visual Studio standart edition.
Today I upgraded to Windows Vista 64 bits, with Visual Studio Professional.
I deleted all .obj, .exe, *.dll files, bin/obj folders.
And rebuild and run...
I have this exception at startup with one of my Managed C++ dlls...
BadImageFormatException was unhandled
Could not load file or assembly 'NScribe, Version=1.0.2635.30786,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. An
attempt was made to load a program with an incorrect format.
Any tips?
|
|
|
|
|
Have you solved this?
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
simple!
While C# assembly don't target any architecture by default, Managed C++ assembly should target a given architecture.
For my Managed C++ I targeted x86 / 32 bits.
Now, all I need is set my main / starting / exe C# assembly affinity to x86 as well (in project properties => build => platform target combo box )
Otherwise, what will happen, is the C# assembly will start as a 64bits executable and will have the aforementioned problem when trying to load a 32bit Managed C++ dll..
|
|
|
|
|
I'll have to keep that in mind with any 32->64 bit work I may run into. Glad you got it figured out.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Hey guys,
Im having a problem with the CImage::GetBits(). Im opening a TIFF file using a CImage object, and i want to take information from this image for use in another function. Here is whats happening.
unsigned char* chBitBuffer = new unsigned char;<br />
chBitBuffer = (unsigned char*)image->GetBits();
This compiles, and appears to work fine, but after several access violations I went a bit deeper.
image's height = 1179, width = 673, bits per pixel = 32.
So Im assuming that the number of pixels = height * witdth. Number of pixels * 4 = total number of bytes, since each pixel is 4 bytes (32/8).
The problem comes in when I try to access the data returned from GetBits(). The buffer only has a length of 3224 in this example, when my calculations say it should be as long as the number of bytes(3173868).
Any clues to what may be going on here?
I win because I have the most fun in life...
|
|
|
|
|
VonHagNDaz wrote: unsigned char* chBitBuffer = new unsigned char;
chBitBuffer = (unsigned char*)/*the image*/image->GetBits();
Why you are allocating memory on heap here ? Actually, GetBits returns address to buffer.
Its should be something like this,
BYTE *pBits = (BYTE*)m_image.GetBits();
p.s. Questions not involving CLI should be asked in VC++[^] forum.
|
|
|
|
|
im being called to a meeting, i will test this as soon as i can get back to my desk.
about the wrong forum, apparently i miss clicked, the vc++ is the link above this forums, sorry
I win because I have the most fun in life...
|
|
|
|
|
In addition to prasad_som's reply...
The total number of pixels should be determined by (pseudocode):
ABS(CImage::GetPitch()) * CImage::GetHeight()
Also, for bottom-up DIBs (CImage::GetPitch() is negative), CImage::GetBits() will return a
pointer to the last row of bits.
Where are you getting the value for the length of the buffer?
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
to get the length i just put together a "stupid" for loop
for(i = 0; i < 9999999; i++)
buffer[i] = 0;
then i let it go until it threw the out of bounds exception
I win because I have the most fun in life...
|
|
|
|
|
So did GetBits() return a pointer to the last row of pixels?
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
oh, sorry i left that out, the image is bottom up, pitch = - 2692, which is also the size i calculated for a scanline of the image +2692.
I win because I have the most fun in life...
|
|
|
|
|
VonHagNDaz wrote: the image is bottom up, pitch = - 2692
Then CImage::GetBits() returns a pointer to the last row of pixels.
To get the beginning of the buffer I suppose something like this would work:
BYTE *pBits = (BYTE *)image.GetBits() + (image.GetPitch() * (image.GetHeight() - 1))
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
alright, im now using the pointer to the pixels, and accessing them using:
<br />
BYTE* pHold;<br />
<br />
int nScanlineIndex = 0;<br />
<br />
while(nScanlineIndex < nTotalBytes)<br />
{<br />
for(int j = 0; j < nScanlineSize; j++)<br />
{<br />
pHold[j] = pBits[nScanlineIndex];<br />
nScanlineIndex++;<br />
}<br />
<br />
scanline->data = (char*)&pHold;<br />
<br />
if(!dither->PerformDither(scanline, ditheredScanline) == S_OK)<br />
return false;<br />
<br />
memset(pHold, 0, nScanlineSize);<br />
}<br />
scanline index counts the bytes of the entire image,which i use to keep track of the position of the byte array. I then transfer the information to the pHold buffer, when is large enough to hold the data of one scanline. the rest is calls to functions of another class that i am using the information for.
I win because I have the most fun in life...
|
|
|
|
|
Is it working? Is nScanlineSize the absolute value of the stride/pitch?
You don't show pHold being allocated so the code as shown should crash.
Also this doesn't look right: scanline->data = (char*)&pHold;
If scanline->data needs a pointer to the pixels then it should be scanline->data = (char*)pHold;
As shown, you are assigning scanline->data the address of the pointer, cast to a char*.
Maybe that's the way it should be but it looks suspicious.
Here's a simplified version of your code, taking advantage of the signed GetPitch() value.
Note that you don't nned to know if GetBits points to the last row or the first row in memory
because GetPitch() will move the pointer in the right direction:
BYTE *pBits = (BYTE *)image.GetBits();
int nScanlineSize = (image.GetPitch() > 0) ? image.GetPitch() : -image.GetPitch();
BYTE *pHold = new BYTE[nScanlineSize];
for (int nCurRow = 0; nCurRow < image.GetHeight(); ++nCurRow)
{
memcpy(pHold, pBits, nScanlineSize);
scanline->data = (char*)pHold;
if(!dither->PerformDither(scanline, ditheredScanline) == S_OK)
{
delete[] pHold;
return false;
}
pBits += image.GetPitch();
}
delete[] pHold;
Do you need to copy the rows of pixel data to a buffer (does dither->PerformDither alter the
source data)? If not, then you could simplify the loop.
BYTE *pBits = (BYTE *)image.GetBits();
for (int nCurRow = 0; nCurRow < image.GetHeight(); ++nCurRow)
{
scanline->data = (char*)pBits;
if(!dither->PerformDither(scanline, ditheredScanline) == S_OK)
return false;
pBits += image.GetPitch();
}
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Hi All,
I'm trying to overload the assignment (=) operator so that I can achieve the following:
int x = myclass;
instead of:
int x = myclass.Value();
I am implementing it as follows:
class CMyClass
{
private:
int m_nValue;
public:
int& operator=(CMyClass& class);
int Value() { return m_nValue; };
};
int& CMyClass::operator=(CMyClass& class)
{
return class.Value();
}
But I keep on getting a compiler errors either saying that there is no suitable conversion, or that it cannot convert from CMyClass to int.
Clearly my syntax (or something) is screwed, so how can I fix it ?
Thanks
OD
|
|
|
|
|
This forum is meant for managed C++. You have rightly asked it in VC++[^] forum. So, please dont cross-post.
|
|
|
|
|
How can i get the system time?
|
|
|
|