|
Well i have this perfectly terible text type game that, for testing purposes i want to have a DOS version of. (At the moment its just a console app, not DOS compatible)
Here is a sample of the code, and yes its pretty much all like this:
********************************************************************
//The text based carrot game brought to you by me
#include <iostream>
using namespace std;
int main()
{
char a [50];
char b [50];
char c [50];
char d [50];
char e [50];
char f [50];
char g [50];
char h [50];
char i [50];
char j [50];
char k [50];
cout <<"This game was written by Some Guy on forrandomjunk at freewebs\nHELLO and welcom to the CARROT ADVENTURE TRILOGY wich contains all 3 carrot advantures. Enjoy.";
cout <<"\n\nYou are a carrot with no family and no friends and are rather quite lonely, have a look for an inanimate abject to be your new friend, what can you see?\n";
cin.getline (a,50);
cout <<"\n\nCONGRATULATIONS you have found the ";
cout <
|
|
|
|
|
If i get it right, you want to hawe DOS native.
1. .NET framework doesn't support DOS. Command namespace is for framework
2. For cout application use #include <iostrean>
3. Visual Studio will not compile DOS application
4. If you realy want. get DOS c++ compiler, or get like MASM, DASM, TASM assemblers.
|
|
|
|
|
Hi all,
I asked this in another forum but found no answers, so here goes.
What I need to do is store the hex value as a string so I can set a textbox text element to that string. So I'm looking to do something like
System::Byte b = 252;
System::String* s = b (formatted as hex value);
then
textBox1->Text = s;
Does any of that make sense??
|
|
|
|
|
Check This sample:
int q;<br />
q = 44;<br />
String *w = String::Format("{0:x}", __box(q));
This is the key for Conversion {0:x}: Zero means first value, x means it vill conver to hex
C++ Syntax to convert from Hex is
int q = 0xfc;
q = 44
Console::WriteLine(w);
Does this help
|
|
|
|
|
Thanx for the reply. What does the _box(q) bit do??
|
|
|
|
|
q is int
But i should pass Object to String::Format so __box does the job
|
|
|
|
|
Ah, that makes things a bit clearer.
Thanx for the help.
|
|
|
|
|
Hi,
I have a problem when I add an unmanaged character array as an member to a managed class. Here's a simple example:
__nogc class Foo
{
public:
static void Test(char* sz)
{}
};
__gc public class Bar
{
public:
void TestFunc1()
{
char buffer[100];
Foo::Test(buffer);
}
char anotherBuffer __nogc[100];
void TestFunc2()
{
Foo::Test(anotherBuffer);
}
}; While there's no problem with Bar::TestFunc1 , Bar::TestFunc2 won't compile. The error message is error C2664: cannot convert parameter 1 from 'char [100]' to 'char *'. The only difference is that in the first case the char array is allocated on the stack, while in the latter it's a member of the class.. However, if I change the call to
void TestFunc2()
{
Foo::Test(&anotherBuffer[0]);
}
, I get the message error C2664: cannot convert parameter 1 from 'char __gc *' to 'char *'.
Any help is appreciated.
Regards
Thomas
Disclaimer: Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.
|
|
|
|
|
Hello,
I was wondering if the following thing can be managed by using c++.
I have two unmanaged classes. Lets call them A and B. Class B inheritance from A.
A has a method for example ShowMeSomeText() and method B has another method ShowMeSomeMore()
If i want to create a managed wrapper, i will create two new managed classes A and B (ManagedA and ManagedB). ManagedB will have an inheritance of ManagedA.
Inside both classes are declarations of the unmanaged object A and B (so ManagedA has a private declaration of unmanaged object A and the same for ManagedB but with object B)
Now i want create in for example a C# program a new instance of object ManagedB and want to call the method ShowMeSomeText() (which is from the class A). This will not work correctly because ManagedB will call the method from ManagedA but this will use the unmanaged object A and this will go wrong. How can this be solved?
Hope somebody can help me? Thanx
|
|
|
|
|
Hi,
I am new to C++ & MC++. I am trying to write a wrapper class for exsiting code which uses libraries(Adobe Framemaker) to open documents. These libraries are written in C++.
The code is :-
......
public __gc class Framemaker
{
bool ConnectToFrameSession(String* strProgID)
{
char* strProg = (char*)(void*)Marshal::StringToHGlobalAnsi(strProgID);
ConnectToFrame(strProg);
return true;
}
......
int ConnectToFrame(char *strProg)
{
StringT opt_progid;
CLSID pclsid;
LPOLESTR progStr;
HRESULT res;
F_ObjHandleT docId;
// Get the process name.
opt_progid = F_StrCopyString((StringT)strProg);
// Convert the process name into a GUID
progStr = (OLECHAR*)malloc( WBUFLEN*sizeof(wchar_t) );
if(0 == MultiByteToWideChar(CP_ACP, 0, (char *)opt_progid, -1, progStr, WBUFLEN ))
{
fprintf(stderr, "failed to allocate\n");
return(1);
}
.......
Now the code bombs while doing a malloc or calling any native frame functions in the function above. It says Object Not Set or NullRefernecce Exception.
Is it beacuse i am trying to mix managed and unmanaged code?
How shld i go abt solving ths problem ?
Also this code runs fine if i make a console application & run it.
I am trying to make wrapper dll which would be calkled by C#.
Only differnec i see is __GC.
Pls guide me.
Thanks,
Gurminder
|
|
|
|
|
Is there nobody who can help me on this ?
|
|
|
|
|
Interop is what turns most coders away from Managed C++ .NET. It's complicated and in the case of existing COM and C++ libraries, with lots of User Defined Types (that are often NOT compatible with the Common Language Runtime) involves some extensive marshalling and data manipulation to get things to work adequately.
When you say the code works fine in a console application, does that mean a console app that does NOT have the /clr switch added to the command line? Console apps can be either managed or unmanaged.
When using a native C++ function in a managed application, you must import it using the [DllImport] attribute (which lives in System::Runtime::InteropServices, and you must include this namespace in your code or use fully qualified names).
You might want read this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconconsumingunmanageddllfunctions.asp[^]
|
|
|
|
|
Thanks for replying.
But my problem persists.
Actually I have tried both ways. One using PInvoke & the other using Managed Wrappers. In both the approaches, I am able to enter the unmanaged function, pass data. But, moment I call the frame APIs or try using new, malloc etc it bombs throwing NullRefernceExcpetion.
In the console applictaion, I complied it using /clr.
I run it & it interacts with the framemaker perfectly.
Frame maker APIs are written in C/C++.
My objective is to call the Framemaker APIs from C#.
What is the best way to this ?
What i belive is that i can get a resoltuion if i m successful in migrating the EXE as a .Net Dll. But, I have tried both ways & I am not able to go ahead because of the issue.
I read it on the net that such exceptions could be raised by something called as Access Violations in the unmanaged code. But, I dont know how to resolve it.
|
|
|
|
|
Some suggestions:
I am unfamiliar with the Adobe Framemaker DLLs, but I'm guessing they are COM libraries. Generally, when you get a NullReferenceException, as you no doubt are aware, you failed to correctly instatiate the COM object or Interface that you must obtain (by calling Query Interface) in order use the method. In your code, you could handle the exception by outputting the exception to a message box or something similar.
malloc is deprecated in C++, and should NOT be used in .NET (although you can use the appropiate headers that define the malloc memory allocator) it is not recommended. Instead use the new operator to instantiate objects, and then -> pointer syntax to invoke methods.
If you are dealing with a COM type library, try using the TlbImp.exe that is included with the Framework SDK and the .NET Framework install. This utility will convert a type library into a .NET assembly that can be referenced directly in source code and used as if they were .NET Framework types. You can then examine the types, methods, and all associated elements in the IL Disassembler, which is a great help.
However, none of the above explains why your code would work in a managed console application, and why it would fail in (what I'm assuming is a managed forms application). I'm guessing that you are leaving out some critical piece of information.
|
|
|
|
|
I tried using ToolboxItem(false) in Managed C++, but it gave me a compiler error:
"error C3725: 'System::ComponentModel::ToolboxItemAttribute': cannot resolve attribute overload".
Please Help
Thank You
tomand
|
|
|
|
|
hi
i want to know what is difference b/w visual c++ and managed c++, is there is lot of difference b/w visual c++ and managed. any tutorial for managed c++.
ddd
|
|
|
|
|
Managed C++ is C++ that compiles to the common language runtime instead of native byte code. Disadvantages: it will be slower. Advantages: you can use the .NET framework to get support for things like regex. Stuff that could be an advantage, based on your point of view: garbage collection.
Managed C++ has not fared well in the marketplace. I don't use it, if I want MSIL, I write C#. If I want speed, I use C++.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I was trying to write the string object and ran into trouble. I'm getting run-time error. The run time error says: blah blah... the memory could not be "read".
I'm using MinGW g++ to compile this program. The program is actually much much longer but i deleted everything that used to be there so it is easier to figure it out.
The run-time error occurs inside of the c_str() function.
But it happens before leaving the substr() function (which calls the c_str() function)
The c_str() function works without generating runtime errors sometimes.
here is the output of my program:
in c_str(): string=this, was, a, test
before new char[18]
after new char[18]
after data is copied.
out c_str()
from main(): this, was, a, test
in substr:
new char[8]
after new char[8]
leaving substr
in c_str(): string=this, wa
before new char[8]
after new char[
and then the runtime error occurs.
So, basically, I get runtime error on the line of code that says:
tmpStr = new char[size]; (inside of c_str()), but why would new char[8] cause a runtime error?
It makes no sense to me everything looks correct to me its driving me insane.
Please help.
|
|
|
|
|
I think i screwed up and posted this message in the wrong section of this website. Maybe it should be under: ATL / WTL / STL
I know people really get upset when users like me do this, but now its too late. I appologize for the mistake.
|
|
|
|
|
I am taking C++ and does anybody know how to make a password code to read a encrypted password simple and easy.
Any suggestions would be helpful.
|
|
|
|
|
where do you hope to read it from ? Do you want to decrypt it, encrypt it, or both ? As you're asking in the managed C++ forum, the .NET framework provides a namespace full of cryptography APIs. As it seems you're 'taking C++', I assume you've asked in the wrong area, and your question relates to ANSI C++. If you could perhaps clarify where you want this password to come from and go to, and what you want to happen to it along the way, perhaps I can help you further.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
This may seem easy, but I swear I cannot find a simple answer.
I have a directory which I plan to make readable by all, but writtable only by Admin group. I need, whne I create files, with code, protect those files from being written by any except Admin. I would also like to make it readable by only Admin and an Operators group if possible.
Can someone give me a clue on what classes to use, and / or a pointer to a web site with an example.
TIA
|
|
|
|
|
I'm looking for a way to send a formated string to the printer using mc++. I have looked into MFC and it seems pretty in depth. Any advise would be greatly appreciated.
Thanks
|
|
|
|
|
MFC printing is easy. There are a couple of helper classes on this site, but just adding support with the wizard gives you the methods you need, you end up printing in your main onpaint method, from memory, and some other methods just set up the printer for you.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How to Print a file By a program Using C++ Ver. Borland 5.2.
Please Send me a Function that prints a given file object.
Thank You.
Dohan
|
|
|
|