|
Hi!
Recently i downloaded an article from this page. This project was programmed in C++ with managed extensions and serves as a .NET Wrapper around a existing C++ implementation of random generators and distributions.
I added this project to my solution that consist of a C# windows application. Under VS.NET 2003 everything worked well and i could use the wrapped random generators and distributions.
Unfortunately, i had to move my solution back to VS.NET 2002. My C# windows application still works well, but the downloaded project doesn't get compiled. I receive the following errors, which i noted besides the lines that generate them:
<br />
template<class T><br />
struct ptr_helper<br />
{<br />
typedef T value_type;<br />
typedef T& reference_type;
typedef const T& rvalue_type;
static reference_type ref(T& r) { return r; }
static const T& ref(const T& r) { return r; }
};<br />
This struct is declared in a header-file of the existing C++ implementation that gets wrapped by the downloaded project.
Why can i compile this under VS.NET 2003 but not in VS.NET2002? What i can i do?
THX in advance
|
|
|
|
|
Hi, I have program written in C#. I want to use some functions from it. I have DLL, but not sure how I can call that functions from C++ application. If some one can help or direct me to the sample code.
Thanks
|
|
|
|
|
Not exactly sure. Try something like:
<br />
#using <mscorlib.dll><br />
#using <System.Windows.Forms.dll><br />
using namespace System;<br />
using namespace System::Windows::Forms;<br />
#using <MyCSharp.dll><br />
using namespace MyCSharp::MyCSharpNamespace;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
#pragma push_macro("new")<br />
return 0;<br />
#pragma pop_macro("new")<br />
}<br />
Don't forget to set Project Properties:
Configuration Properties | General | Use Managed Extensions = Yes
C/C++ | General | Debug Information Format = Program Database (/Zi)
C/C++ | Code Generation | Enable Minimal Rebuild = No
C/C++ | Code Generation | Basic Runtime Checks = Default
Which is a best guess based on Tom Archer's book:
Extending MFC Applications with the .NET Framework[^]
Sincerely,
-Ron
|
|
|
|
|
|
Did it work?
Sincerely,
-Ron
|
|
|
|
|
|
i have a mixed mode dll which defines some functions in a .def file. my unmanaged app loads the dll dynamically with a call to LoadLibrary() and calls these functions. some of my functions are called correctly, but some are not. the unmanaged app seems to be able to find all the functions, but for some reason, can't call some of the functions. anyone have an idea as to why that would be??
|
|
|
|
|
Hi, everyone!
I'm a newbie in MC++ and Win32 API programming. I want to create a Bitmap object with an image of a Windows.Forms form. So far I've written the following code:
<br />
Bitmap *De3DFormView::GetWindowBitmap(Form *pForm)<br />
{<br />
System::Drawing::Graphics *pGraph = Graphics::FromHwnd(pForm->Handle);<br />
int pSrc=pGraph->GetHdc().ToInt32();<br />
<br />
HDC destDC;<br />
HBITMAP destBmp;<br />
DWORD err;<br />
<br />
destDC = CreateCompatibleDC((HDC)pSrc);<br />
destBmp = CreateCompatibleBitmap((HDC)pSrc, pForm->Width, pForm->Height);<br />
<br />
SelectObject(destDC, destBmp);<br />
<br />
SendMessage(HWND((int)pForm->Handle), WM_PRINT, WPARAM(destDC), PRF_CLIENT | PRF_NONCLIENT | PRF_CHILDREN | PRF_ERASEBKGND);<br />
<br />
Bitmap *pB = Image::FromHbitmap(destBmp);<br />
<br />
pGraph->ReleaseHdc(pSrc);<br />
pGraph->Dispose();<br />
<br />
return pB;<br />
}<br />
When I run it, I get the following exception "ArgumentException" with message "hdc". Debugging shows that this error occurs after the "SendMessage" call.
The other thing is that when I step through the "destDC = CreateCompatibleDC((HDC)pSrc);" line, I notice that destDC has "undefined value".
Can you tell me what I am doing wrong?
Regards,
Serge (Logic Software)
|
|
|
|
|
The search function I have isn't working, possibly because of the scope of the while & if functions or that I am using the wrong functions.
Please see if a different [U]search [/U] or maybe if the [U]code[/U] needs changing, Thank you button.
[code]
#include <iostream.h> //Pre Processor Directives
#include <fstream.h> //Libary for Input funcitons
#include <iomanip.h> //Input/Output manipulation libary
#include <string.h>
void main()
{
ofstream file("Database"); //Create a new file
file.open("Database");
char* name[9];
name[0] = NULL;
name[1]="HP4p";
name[2]="HP5L";
name[3]="HP6p";
name[4]="Cannon2A";
name[5]="Cannon3B";
name[6]="Epson2";
name[7]="Epson3";
name[8]="Epson4A";
float cost[9];
cost[1]=32.99;
cost[2]=24.99;
cost[3]=30.00;
cost[4]=23.45;
cost[5]=31.99;
cost[6]=25.00;
cost[7]=30.00;
cost[8]=27.99;
int quantity[9];
quantity[1]=100;
quantity[2]=50;
quantity[3]=75;
quantity[4]=30;
quantity[5]=80;
quantity[6]=10;
quantity[7]=25;
quantity[8]=30;
char name8[13]="Cartridge";
char cost8[11]="£00.00p";
char quantity8[12]="Quantity";
{
for (int x = 1; x < 8; x++)
file<<name[x]<<' '<<cost[x]<<' '<<quantity[x];
}
file.close(); //close the file
int num=0,x;
char sought[15]; //Declare Variables
cout<<"Display all records press '1' "<<"Do a Search press '2' "<<" '0' to Quit "<<endl;
cin>>num;
if (!num==0)
{
if (num==1)
{
cout<<"Total Items in stock \n"<<endl<<endl;
ifstream file("Database",ios::in); //ios::in for input from the file
cout<<setw(20)<<setfill(' ')<<setiosflags(ios::left)<<name8;
cout<<setw(10)<<setfill(' ')<<setiosflags(ios::right)<<cost8;
cout<<setw(12)<<setfill(' ')<<setiosflags(ios::right)<<quantity8<<endl;
for (int x = 1; x < 8; x++)
{
cout<<endl<<setw(20)<<setfill(' ')<<setiosflags(ios::left)<<name[x];
cout<<setw(8)<<setfill(' ')<<setiosflags(ios::right)<<cost[x];
cout<<setw(8)<<setfill(' ')<<setiosflags(ios::right)<<quantity[x];
}
}
cout<<endl<<endl<<"Display all records press '1' ";
cout<<"Do a Search press '2' "<<" '0' to Quit "<<endl;
cin>>num;
if (num==2)
{
cout<<endl<<"To search by the printers make type in the name e.g HP4p: Type 'N' for no more"<<endl;
cin>>sought;
ifstream file("Database"); //open file for input FROM file
//while(!file.eof())
//{ //file.seekg(0); //set file pointer to first character
if (strcmp(sought,"N")!=0)
{
delete [] name[0]; //it is safe to call delete [] on NULL pointer.
name[0] = new char[strlen(sought)];
strcpy(name[0],sought);
x=8;
while (strcmp(name[x],sought)!=0)
x--;
if (strcmp(name[x],sought)==0)
{
cout<<endl<<setw(20)<<setfill(' ')<<setiosflags(ios::left)<<name[x];
cout<<setw(8)<<setfill(' ')<<setiosflags(ios::right)<<cost[x];
cout<<setw(8)<<setfill(' ')<<setiosflags(ios::right)<<quantity[x]<<endl;
}
else
{
cout<<"No such item in stock"<<endl<<endl;
}
file.close();
cout<<"Display all records press '1' ";
cout<<"Do a Search press '2' "<<" '0' to Quit"<<endl;
cin>>num;
}
}
}
}[/code]
|
|
|
|
|
Hello people !
It seems that either my Visual Studio .Net 2003 is missing a critical component or then I am simply too dumb to use it..
I'm trying to write a MC++ Web Service using some of the tutorials available here on CodeProject, but in the list of available projects under "Visual C++ Projects", I only have "ASP.NET Web Service", "ATL Server Web Service" and "Windows Service (.NET)". Other project types refer to different applications alltogether (MFC, empty projects etc)
Which one of these is considered as _the_ Managed C++ Web Service ? I believe it's the ASP.NET type, but I'd like to have a confirmation.
Following the same route, and by following Chris Maunder's example on writing a web service with C#, I was unable to find the "Web Service" project under "Visual C# Projects".. The only options available are "ASP.NET Web Application", "ASP.NET Web Service" and "Web Control Library", among the standard ones.
Any clues ?
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
You want the ASP.NET Web Service. It creates a skeleton web service for you which runs under IIS.
|
|
|
|
|
I have been trying to get the search facility below to work but it throws an error because of the memory being allocated I think.
Please Please take a look at the code and see you can do anything...Much appreciated. Buttons
#include <iostream.h> //Pre Processor Directives
#include <fstream.h> //Libary for Input funcitons
#include <iomanip.h> //Input/Output manipulation libary
void main()
{
ofstream file("Database"); //Create a new file
file.open("Database");
char* name[9];
name[1]="HP4p";
name[2]="HP5L";
name[3]="HP6p";
name[4]="Cannon2A";
name[5]="Cannon3B";
name[6]="Epson2";
name[7]="Epson3";
name[8]="Epson4A";
float cost[9];
cost[1]=32.99;
cost[2]=24.99;
cost[3]=30.00;
cost[4]=23.45;
cost[5]=31.99;
cost[6]=25.00;
cost[7]=30.00;
cost[8]=27.99;
int quantity[9];
quantity[1]=100;
quantity[2]=50;
quantity[3]=75;
quantity[4]=30;
quantity[5]=80;
quantity[6]=10;
quantity[7]=25;
quantity[8]=30;
char name8[13]="Cartridge";
char cost8[11]="£00.00p";
char quantity8[12]="Quantity";
{
file<<name<<' '<<cost<<' '<<quantity;
}
file.close(); //close the file
int num=0,x;
char sought[15]; //Declare Variables
cout<<"Display all records press '1' "<<"Do a Search press '2' "<<" '0' to Quit "<<endl;
cin>>num;
while(!num==0)
{
if (num==1)
{
cout<<"Total Items in stock \n"<<endl<<endl;
ifstream file("Database",ios::in); //ios::in for input from the file
//while(!file.eof())
cout<<setw(20)<<setfill(' ')<<setiosflags(ios::left)<<name8;
cout<<setw(10)<<setfill(' ')<<setiosflags(ios::right)<<cost8;
cout<<setw(12)<<setfill(' ')<<setiosflags(ios::right)<<quantity8<<endl;
for (int x = 1; x < 9; x++)
{
cout<<endl<<setw(20)<<setfill(' ')<<setiosflags(ios::left)<<name[x];
cout<<setw(8)<<setfill(' ')<<setiosflags(ios::right)<<cost[x];
cout<<setw(8)<<setfill(' ')<<setiosflags(ios::right)<<quantity[x];
}
}
cout<<endl<<endl<<"Display all records press '1' ";
cout<<"Do a Search press '2' "<<" '0' to Quit "<<endl;
cin>>num;
if (num==2)
{
cout<<endl<<"To search by the printers make type in the name e.g HP4p: Type 'N' for no more"<<endl;
cin>>sought;
ifstream file("Database"); //open file for input FROM file
//file.seekg(0); //set file pointer to first character
while (strcmp(sought,"N")!=0)
{
strcpy(name[0],sought);
x=9;
while (strcmp(name[x],sought)!=0)
x--;
if (strcmp(name[x],sought)==0 && x>0)
{
cout<<endl<<setw(20)<<setfill(' ')<<setiosflags(ios::left)<<name;
cout<<setw(8)<<setfill(' ')<<setiosflags(ios::right)<<cost;
cout<<setw(8)<<setfill(' ')<<setiosflags(ios::right)<<quantity<<endl;
}
else
{
cout<<"No such item in stock"<<endl<<endl;
}
}
file.close();
cout<<"Display all records press '1' ";
cout<<"Do a Search press '2' "<<" '0' to Quit"<<endl;
cin>>num;
}
}
}
|
|
|
|
|
I had to add #include <string.h> to get it to compile.
strcpy(name[0],sought);
That statement is probally where the problem is. name[0] is an unintialized pointer, so when you try to copy a null terminated string into it you will be accessing a random location in memory.
One solution is to initalize it to something.
name[0] = new char[15];
You will have to remember to release that memory before you are done.
delete [] name[0];
Another solution is to just assign that pointer to point directly to the sought string.
name[0] = sought;
This seems a little strange, but it is pretty effecient. Also, you have to worry about freeing it later.
The next problem I get is with this statement.
while (strcmp(name[x],sought)!=0)
The reason is that x is initialized to be 9, but the highest possible index for name array is 8. Rember, indexing starts at 0. So, change x=9; to x=8;
There are a couple other problems with that code, but this will at least get you past the memory problems.
|
|
|
|
|
The first problem that I see is you're not creating the char pointer for name[0]. The other pointers are initialized to the constant strings. My recommendation is get rid of the char* and use std::string. It has a comparison operation implemented for you. Also your code will be much cleaner.
Phil
|
|
|
|
|
Yes, the char* name[9] area is the problem. When you assign stuff to it, you need to allocate memory. One way, as another suggested, is to use std::string instead of char *. You can also make these arrays constants. E.g.,
const char* name[9] =
{
"Lexmark Z25",
"HP4p",
"HP5L",
"HP6p",
"Cannon2A",
"Cannon3B",
"Epson2",
"Epson3",
"Epson4A"
};
Note I added an item at the begining, this is beause if the array isn't 9 items, the compiler will complain. Arrays start at index 0, btw. (It also happens to be the printer I have. )
You can use this same trick with the other arrays, for consistency, but for the strings, at least, it saves you the hassle of having to allocate memory and stuff.
Sometimes I feel like I'm a USB printer in a parallel universe.
|
|
|
|
|
Hi guys,
I am new to using inheritance in C++ programming .I am trying to implement some of the missing methods in C++ string class using inheritance.Even thoughi have coded the methods i am not able to apply those on the string data type,.Can any of you help me out on this
Thanks
Sas
|
|
|
|
|
Ummm - what missing methods are you referring to? Are you talking about std::string, or MFC/ATL CString?
Phil
|
|
|
|
|
I am talking about methods like rightJustify,strip() etc.. and i want to implement them in the inherited class.I wanted toknow how the declaration & implemantation of header will be..btw, am talking about std::string
your help will be greatly appreciated!!
Thanks
Sas
|
|
|
|
|
Dear forum members,
I have controls (UserControl) designed in C#.
Can anyone tell me how I can embed them in MFC dialogs/views ?
Any sample code will be very helpful.
Thanks in advance.
|
|
|
|
|
Hi,
I am working on an unmanged user interface .I am using the services of a COM Executable that is also unmanaged.
BUt to get the handle of the Com executable ,I have to go through Managed DLL(i.e this is the requirement).
I am able to retrieve the handle successfully, but some methods are failing.
The HR error value in these is 0x80131531
MSDN says that this exception thrown by the marshaler when it encounters an argument of a variant type that
can not be marshaled to managed code
I am helpless about this error.
Can anybody suggest some way to rectify it?
Thanks in Advance!
Sanjay
|
|
|
|
|
Can someone help me? I have VS C++ 2003. Am try to make a manged project. But there is no Managed C++ Application in the project box. What do I need to do.
|
|
|
|
|
I have two projects, one unmanaged. The other is managed using stl lists of classes declared in the unmanaged project. When building the unmanaged project, anywhere the lists are used produces these linker errors.
MotionTimelineControl.obj : error LNK2022: metadata operation failed (80131187) : Inconsistent method declarations in duplicated types (types: tools.thoth.MotionEventController; methods: .ctor): (0x06000013).
MotionTimelineControl.obj : error LNK2022: metadata operation failed (80131187) : Inconsistent method declarations in duplicated types (types: tools.thoth.MotionEventController; methods: load): (0x06000017).
MotionTimelineControl.obj : error LNK2022: metadata operation failed (80131187) : Inconsistent method declarations in duplicated types (types: tools.thoth.MotionEventController; methods: getEventItr): (0x06000022).
MotionTimelineControl.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: tools.thoth.MotionEventController; fields: m_event): (0x04000011).
tools.thoth.MotionEventController, uses lists of classes from the unmanaged project, and MotionTimelineControl.obj is from a class that takes a MotionEventController as an argument to two methods.
The only solution i have found to get around the linker error is in the unmanaged project is to create a class that is not used (the constructor is private), with public stl lists with the classes used in the managed project. i.e. (MotionTimeLineEvent is a class declared in the unmanaged project.)
if the managed project uses
void doFunc(list<motiontimelineevent>::iterator iter);
then declaring a public variable in the unused class:
list<motiontimelineevent>::iterator m_iter;
would clear up any linker errors having to do with lists of MotionTimelineEvents.
if anyone has any clue on how to resolve the inconsistent metadata, please throw me a bone, i have tried most available solutions but, any suggestions would be greatly appreciated.
|
|
|
|
|
while I'm running my app, everything seems to be working fine. Once I exit the app I get the following messagebox:
INTERNAL ERROR<br />
<br />
Unhandled exception in Debugger::HandleIPCEvent<br />
<br />
Event id = 0x225<br />
<br />
Exception code = 0xc0000005,Eip = 0x7928c531<br />
<br />
ProcessID = 0x4a4(1188), Thread id = 0x384(900)
then I get a messagebox telling me the following:
An unhandled exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
I recently deleted some controls and their message map entries for a dialog, and I wasn't getting this error before, does anyone know what this might be?
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Hai Friends,
In my project i have lot of drwaing in a MDI child form. The form has scrollable contents also.
I want to show miniature of the drwaing form in child control something like picturebox or some other containers.(show the full drawings)
Anyone have any idea??
Thanks in advance
Anish
|
|
|
|
|
I am using alarm() to time a process.
Is there something with which i can measure by milliseconds ?
The alarm() in C++ allows only seconds and not anything lesser than that.
I did try ftime() and time(),But i need something to timeout automatically.
I am using RH linux and g++ 3.2
Thanks
|
|
|
|
|