|
I need to get a string from an editbox and write it to a binari file. The only problem i'm getting is that my string ends with 0D 0A instead of 00 and it's very important that it ends with 00. Is ther a way to do that easily.
I'm using Cfile and CString only because that the only way i found to write japanese correctly to a binary file and i know it's looks ugly in a managed project.
Here is the importants parts of the code
CFile fVampFile;
char * cInfo = "";
int iEnd;
fVampFile.Open(csFilename,CFile::modeWrite | CFile::shareExclusive | CFile::modeCreate | CFile::typeBinary )
cInfo = (char*)Marshal::StringToHGlobalAnsi(eSpeech->Text).ToPointer();
iEnd = strlen(cInfo);
fVampFile.Write(cInfo,iEnd);
|
|
|
|
|
Hi, I'd need some help with my commandline application.
Its basically a contact list application which allows user to choose to add two types of contacts (club and client).
I wrote the classes for these two. So when the choice is made, a function ADD() is invoked which creates this arrays of type club or client.
The problem is as these object arrays are created within the ADD() function, they have only a local scope so I tried referencing its values so that in the end, the main() function can have have access to them.
But unfortunately the message from the compiler is "referencing an array...."
Is it possible to reference an array so that its scope becomes virtualy global?
If not, what other ways can a variable object within a function be accessed easily by other functions?
|
|
|
|
|
Is this a C++/CLI question, or just C++.
Either way, in this forum or the C++ forum, it sounds like you need to post your code. You can return anything from a method, you can't declare anything in a method and give it scope outside the method without returning it. Returning a pointer makes the most sense ( saves a copy being made ).
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi again...The code is below and i hope it helps clarify my enquiry.I'm new to C++ and all help and suggestions are much appreciated.
*******************code for contact list********************
#include <cstdlib>
#include <iostream>
using namespace std;
class BasicAd{
protected:
string name;
string home_address;
public:
void BasicAd::setValues(string n, string h){
name = n;
home_address = h;
};
void BasicAd::getValues(){
cout<<"name : "<<name<<endl;
cout<<"home address="" :="" "<<home_address<<endl;
};
};=""
class="" clubdir:="" public="" basicad{
private:
string="" member_name;
int="" date_joined;
public:
void="" clubdir::setvalues(string="" n,="" string="" h,="" nm,="" int="" d){
name="n;
home_address" =="" h;
member_name="nm;
date_joined" d;
};
void="" clubdir::getvalues(){
cout<<"name:="" "="" <<name<<endl;
cout<<"home="" "<<home_address<<endl;
cout<<"member="" name:="" "<<member_name<<endl;
cout<<"date="" joined:="" "<<date_joined<<endl<<endl;
};
};="" clientdir:="" client_name;
string="" business_address;
public:
void="" clientdir::setvalues(string="" ha,="" cn,="" ba){
name="n;
home_address" ha;
client_name="cn;
business_address" ba;
};=""
void="" clientdir::getvalues(){
cout<<"\nname:="" "<<home_address<<endl;
cout<<"client="" "<<client_name<<endl;
cout<<"business="" address:="" "<<business_address<<endl<<endl;
};=""
};
void="" add(clubdir&="" [],="" clientdir&="" int&="" size);
void="" edit();
void="" delete();
void="" getoption();
void="" display();
int="" main()
{=""
int&="" sizze;=""
clubdir&="" clubb[size];
clientdir&="" clientt[size];=""
cout<<"....welcome="" to="" the="" contact="" database...."<<endl;
cout<<"-------------------------------------------------"<<endl<<endl;
getoption();
system("pause");
return="" exit_success;
}
void="" add(){=""
string="" name;
string="" ha;
string="" mn;
string="" cn;
string="" ba;
int="" dj;
int="" choice;
clubdir="" club[size];
clientdir="" client[size];=""
cout<<"please="" select="" one="" of="" choices="" perform="" its="" task:="" \nclubdir="" [1]\tclientdir="" [2]:="" ";
cin="">>choice;
if(choice==1){
cout<<"\nEnter number of items for clubDir: ";
cin>>size;
for(int i=0; i<size; i++){
cout<<"\nenter="" values="" of="" clubdir="" "="" <<="" (i+1)="" ":\nname:";
cin="">>name;
cout<<"home address: ";
cin>>ha;
cout<<"member name: ";
cin>>mn;
cout<<"date joined:";
cin>>dj;
cout<<"\n";
club[i].setValues(name, ha, mn, dj);
};
cout<<"\nThe Contact Details addded....";
}
else if(choice==2){
cout<<"\nEnter number of items for clientDir: ";
cin>>size;
for(int i=0; i<size; i++){
cout<<"\nenter="" values="" of="" client="" "="" <<="" (i+1)="" ":\nname:";
cin="">>name;
cout<<"home address: ";
cin>>ha;
cout<<"client name: ";
cin>>cn;
cout<<"business address:";
cin>>ba;
cout<<"\n";
client[i].setValues(name, ha, cn, ba);
};
cout<<"\nThe Contact Details addded....";
};
}; //end of ADD()
void EDIT(){
};
void DELETE(){
};
void DISPLAY(){
};
void getOption(){
int option;
cout<<"Select one of the following options :\nADD - [1] \tEDIT - [2]\t DELETE - [3]: ";
cin>>option;
cout<
|
|
|
|
|
There is an exception caught during loading the Form, but the Form will be loaded no matter what. I want to display that exception Message in front of the Form once the Form is loaded.
If I use message box to display the exception Message inside the Form_load function, the Exception message box is behinde the Form. How can I make it displayed in front of the Form?
|
|
|
|
|
You could add a TextBox to the form and show the message in that TextBox.
|
|
|
|
|
Uhm, the parent form can't have the error message box on it.
I have a class called ErrorScreen displaying error message. Then there is the main menu Form1 (1). the Form invokes function classes(2). These function classes invoke more basic classes(3). These basic classes invoke the ErrorScreen class. But the ErrorScreen instances displays strangely in front of the main menu. The error icon, the text, and the button are not displayed, but empty holes on the ErrorScreen. If the ErrorScreen instances are replaced with Forms::MessageBox::Show(),the error messages are displayed correctly. But I need big size button displayed on the error message screen, therefore I need use the ErrorScreen class created myself.
What senarias I shall look into in order to display those ErrorScreens correctly?
|
|
|
|
|
When I add my assembly to the Toolbox via the Tools | Choose Toolbox Items... dialog, the components in my assembly are added to the General tab. How can I tell Visual Studio 2005 programtically to add my components to some other tab ?
I was expecting some attribute placed before the component class which I could set to tell the Toolbox on which tab I my component would be placed, but I could not find such an attribute. But I am sure their must be some way from within my assembly by which I can direct the Toolbox to place a given component on a particular tab, which would be created for it if the tab does not already exist within the Toolbox.
Edward Diener
|
|
|
|
|
Hello,
I have the following 'effect' with my application, implemented with Managed C++ on Visual Studio 2003.
If I start the application on some computers, MessageBoxes (System.Windows.Forms) are popping up as they are expected to. They show a button and they have a size depending on the message they should show. Only that the text doesn't show. Neither the message nor the OK on the button. The Titlebar is shown correctly. What is causing that kind of problems?
I tested the effect on several PCs already. They all have Windows XP and .NET framework installed (in the correct version). I'm not sure, but I think, the PCs that it's not working on do not have VS2003 installed. However it's working on other PCs that also do not have VS2003.
I made a test application that only gave a MessageBox. It's showing correctly on the development PC but again not on the TestPC(s).
Is it a regional problem? Is it a library problem? Shouldn't those standard library functions (as the MessageBox) not work anywhere. I would doubt if it was my selfmade Messagebox.
Any idea?
Thank you in advance,
dawei
-- modified at 9:38 Wednesday 23rd August, 2006
|
|
|
|
|
Are you passing string literals to the messagebox call? Or are you passing a variable? Try using a constant or a literal - that'd help narrow down the point of error.
|
|
|
|
|
Hi,
yes, I thought of that as well. So I made the test sample using both a constant value ("STRING" as well as S"STRING") and a variable.
Anyway it happens.
I continued my testing and interestingly, although development and testing were made on XP machines, setting the compatibility mode of the application on the test machine stops that error from appearing!
On another website they say that they had similar problems because of a bug in McAfee Anitvirus 8.0. We use that program but our administration always updates that kind of tools. So everyone should have the same version. Hence, either it should work or not work on both machines.
Funny...
Thanks for your answer! It's a strange little problem, but I am happy that at least I have a solution- although not satisfying. If you know the answer, it might also be interesting for other people!
best regards,
dawei
|
|
|
|
|
Is there any way using unasfe (non-managed) raw CPP to temporarily elevate access to s specific function like you can in managed code?
|
|
|
|
|
Ray Cassick wrote: Is there any way using unasfe (non-managed) raw CPP to temporarily elevate access to s specific function like you can in managed code?
Perhaps you could use AdjustTokenPrivileges .
|
|
|
|
|
hi,
i am writing a dll in MC++ for using from C#.
I have a pair of strings and object of class say 'Record', <<string,record>> which should be passed to a dll function. i have learned that SortedList collection class can be used in this scenario. but i dont know how to create SortedList object in C# and how to receive it in managed c++ function. Please guide me on this.
thanks in advance,
Abin
|
|
|
|
|
Can this link help?
Best,
Jun
|
|
|
|
|
yes Jun , it was a very good article
thank u very much !
|
|
|
|
|
I have an unmanaged project that I will to compile in Managed C++. Is it just a matter of adding the /clr switch to the compiler options in VS2005/Project/Properties/C++/Command Line?
Thanks
alias47
|
|
|
|
|
Yes, that is, in theory, correct. However, I'm not sure if that will actually expose anything to the CLR ( if it's a dll ), it will simply make the .NET framework available to your application.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
So, is the solution to create Managed C++ wrapper for each exported routine?
|
|
|
|
|
alias47 wrote: So, is the solution to create Managed C++ wrapper for each exported routine?
What exactly is your scenario? That might help people give a more suitable answer.
|
|
|
|
|
If you want to export C++ methods to be exposed to .NET, then probably, but as Nish said, some more info would help.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks for your help guys. I have a c++ MFC DLL, written in Visual c++ 6.0. This DLL is currently called from an Excel VBA application and has some callbacks back to Excel in it. I have rewritten all of the VBA code into a non-VSTO shared managed add-in in c#, written in VS2005. I want the managed addin to call the c++ DLL the same way VBA used to. In its current form if I add a reference in the managed addin to the c++ DLL, a message says that it is not a valid assembly or COM component. If I compile the c++ DLL in VS2005 without the /clr switch it makes no difference, except that the Excel VBA application does not work anymore. If I try to use a DLLImport with the c++ DLL, I receive a "memory may be corrupt" message. The c++ DLL exports about 30 functions, as specified in a DEF file. Do I need a Managed c++ wrapper around these functions to access them from C#. Is there some boilerplate code to use? Does it depend on what the functions are?
Sample of the first function exported:
extern "C"<br />
short int DLLFUNC FunctionX()
DLLFUNC defined:
#ifndef DLLFUNC<br />
#ifdef WIN32<br />
#define DLLFUNC _stdcall<br />
#else<br />
#define DLLFUNC WINAPI _export // DLL functions are FAR PASCAL _export<br />
#endif<br />
#endif
Regards
alias47
|
|
|
|
|
Hello,
alias47 wrote: Do I need a Managed c++ wrapper around these functions to access them from C#?
Yes.
alias47 wrote: Is there some boilerplate code to use?
Check out this CP article: Using Microsoft Interoperability Libraries.
alias47 wrote: Does it depend on what the functions are?
No.
Best,
Jun
|
|
|
|
|
I *really* need someone to help me out.. I am wasting heaps of time trying to access this unmanaged c++ DLL from C#. It is a showstopper.
Let me check my understanding on a few issues:
IJW: Does IJW mean "Just compile unmanaged c++ code in VS2005" and then reference the unmanaged DLL in C#. If so, this does not work.
COM: How can I tell that the unmanaged c++ DLL is not COM-based? (Apart fromn the message I receive when trying to reference the DLL from C#)
PInvoke: When using this from C# to the c++ DLL, I receive a message about corrupt memory. Is this because the type of the argument is incorrect? In c++ the type is IDispatch. In C# I am passing an object type. In fact it is an Excel.Application type which is being cast to object that I am passing. Will this PInvoke technique possibly work if I pass a different type?
The article http://www.codeproject.com/useritems/usingcppdll.asp seems comprehensive, but I wonder whether I need to do any/all of this.
The unmanaged c++ DLL works prefectly currently with Excel. I guess that is because excel is itself unmanaged? Is the approach found http://groups.google.com/group/microsoft.public.dotnet.languages.vc/browse_thread/thread/8c538b0e1bbf020b/cac8b5f6bb7932ef%23cac8b5f6bb7932ef
too simplistic?
Surely there is an app in vs2005 that autogenerates the managed wrapper? Surely? Like http://www.codeproject.com/dotnet/NativeWrapper.asp
Regards
alias47
|
|
|
|
|
alias47 wrote: IJW: Does IJW mean "Just compile unmanaged c++ code in VS2005" and then reference the unmanaged DLL in C#.
The first half is correct. IJW only compiles unmanaged code and leave it in the unmanaged context. It won't make it callable by managed code, meaning you can't add unmanaged DLLs as references to managed projects.
alias47 wrote: COM: How can I tell that the unmanaged c++ DLL is not COM-based? (Apart fromn the message I receive when trying to reference the DLL from C#)
Your header and source files should indicate COM interfaces and their implementations. If your modules has implemented IDispatch, then the module is a COM-based. Check this site for how to PInvoke COM in managed C++.
alias47 wrote: PInvoke: When using this from C# to the c++ DLL, I receive a message about corrupt memory. Is this because the type of the argument is incorrect? In c++ the type is IDispatch. In C# I am passing an object type. In fact it is an Excel.Application type which is being cast to object that I am passing. Will this PInvoke technique possibly work if I pass a different type?
Probably because the first two issues have not been resolved properly.
Best,
Jun
|
|
|
|