|
Hello ! I am bit confused of allocation of __gc struct arrays, so
I have the following declaration and allocation:
__gc struct MethodTableEntry {<br />
<br />
String* MethodName;<br />
String* ParamName;<br />
};<br />
<br />
<br />
MethodTableEntry *MethodTable[]=__gc new MethodTableEntry*[MethodNumber];
Now I want that ParamName should be an array of 7 strings.
Ex. i want to use the following
MethodTable[1].ParamName[2]=S"This is the 2nd Param of Method No1";
So how can I allocate these string arrays ? I tried a lot, but now I am tired of hunting the proper syntax.
Thanx
|
|
|
|
|
I understand that the equivalent for __gc in VC++ 2005 is ref keyword. Similarly can anyone update me on the equivalent for __gc* in VC++ 2005.
Thanks in advance
Thanks and Regards
Madhu
|
|
|
|
|
madhusri wrote: I understand that the equivalent for __gc in VC++ 2005 is ref keyword. Similarly can anyone update me on the equivalent for __gc* in VC++ 2005.
Thanks in advance
I answered this in the MS forum too. But since you've posted here, and since others may have the same question in future, here's the answer once again :-
A^ a = gcnew A();
The A^ is a handle to the managed object A (similar to __gc* in MC++)
Regards,
Nish
|
|
|
|
|
Sivakumar,
Thanks for your response. I had actually tried with this option earlier. But then i did not get the problem solved. May be i'll try explaning you what i actually need with this code segment so that you can help me out.
The objective is i have to access a dll through C# code. The dll is created from VC++ code. In the C# code i need to pass the address as the function argument. In VS 2003 i could achieve it through the following C++ code segment:
public:void GetIntReturn(int __gc* ivalue)
{
*ivalue=10;
}
Here's the C# code segment calling the corresponding function.
public int GetValueFromC++()
{
int i =0;
GetIntReturn(ref i)
return i;
}
This work fine and this is what i want.
But now i got to do the same using VS2005. As you said earlier i tried replacing __gc* with ^. But when invoking this function in C# it asks me for value type and not reference type. Can you help me out with this please.
Thanks and Regards
Madhu
|
|
|
|
|
Ah ok, the C++/CLI equivalent for that is
void GetIntReturn(int% ivalue)
{
ivalue = 10;
}
Regards,
Nish
|
|
|
|
|
Sivakumar,
Thanks for your response. This worked out well for me.
Thanks and Regards
Madhu
|
|
|
|
|
Thanks we got an idea. but this doesn't work on class ,string and structures
how can this be used for those data types
Regards
Srini
|
|
|
|
|
Sriinii wrote: Thanks we got an idea. but this doesn't work on class ,string and structures
In what way does it not work?
Regards,
Nish
|
|
|
|
|
You have to do the following:
<br />
void GetStringReturn(String^% stringValue)<br />
{ <br />
stringValue = "10"; <br />
}<br />
-- modified at 14:59 Friday 3rd February, 2006
|
|
|
|
|
This is gr8 it is working for me.
Thanks George, Nishant.
Thank u very much
Regards,
Srini
|
|
|
|
|
Does anybody know how to get share permissions?
Kelvin Chikomo
|
|
|
|
|
How to convert binary file to text file in C++?
Premalatha
|
|
|
|
|
What do you mean by this ?
You mean converting an executable (which is a binary file) into a text file for example ?
And what do you mean also by text file ? Something like transforming your binary file into source file or something like that ? (that is not possible, or not easily at least...)
-- modified at 2:55 Tuesday 24th January, 2006
By the way, this is the forum for managed and not the C++ forum. You should post in the future in the Visual C++ forum because your question is purely related to C++
|
|
|
|
|
Could You be more specific, pls ?
What type of binary file u have, and what info is stored in it ?, etc ...
|
|
|
|
|
This program converts a .bin to a readable file but it also increase the overall size(not good) any help or ideas.
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
int _tmain()
{
unsigned char a1[16];
unsigned char a2[16];
unsigned int tempWRITE;
//FILE *in = fopen("c:/test.bin","r");
FILE *in = fopen("c:/test.bin","rb");
FILE *out = fopen("c:/new.txt","w");
while(!feof(in)) {
fread(a1,1,16,in);
a2[0] = a1[3];
a2[1] = a1[2];
a2[2] = a1[1];
a2[3] = a1[0];
a2[4] = a1[5];
a2[5] = a1[6];
a2[6] = a1[4];
a2[7] = a1[7];
a2[8] = a1[9];
a2[9] = a1[11];
a2[10] = a1[8];
a2[11] = a1[10];
a2[12] = a1[14];
a2[13] = a1[12];
a2[14] = a1[15];
a2[15] = a1[13];
fwrite(a2,1,16,out);
}
fclose(in);
fclose(out);
return 0;
}
1. Out of clutter, find simplicity.
2. From discord, find harmony.
3. In the middle of difficulty lies opportunity.
Albert Einstein
three rules of work
|
|
|
|
|
Hi all....
Maybe you all think this is a silly question, but this problem really disturbing me. The problem is set default namespace for multiple class file. The problem is like this :
at the first file i type :
namespace NSA {
namespace NSB {
//Class statement here.
}
}
The problem came when we create a multiple class file (using Project->Add Class menu) but have same namespace like above. Old way is I type the namespace structure like above in every file. Then i thinking if i create more then 10 class file then i must type the same namespace for 20 times (so you know what will came if we create 3 or more namespace level).
I found in the project properties window (not the pop up) the property call "Root Namespace", I have set up like this "NSA" then in evey file i only type namespace "NSB". But then in the object browser only came the "NSB" namespace. (Doesn't help anyway i think).
Please reply soon, OK.
Thanks for help of you all.
|
|
|
|
|
|
Yes. Copy And Paste.
you can name class like:
NSA_class1, NSA_NSB_class2, NSA_NSC_class3.
If you are making more simple program, then one namespace is more than enough.
What kind of program are you making, that you need so much namespace nesting?
I had created a smoll project with a name test.
//test.h
#pragma once
namespace NSA
{
namespace NSB
{
public ref class test1{};
}
namespace NSC
{
ref class test2{};
ref class test3{};
}
}
// tes.cpp : main project file.
#include "stdafx.h"
#include "test.h"
using namespace NSA;
using namespace NSA::NSB;
using namespace NSA::NSC;
#include "Form1.h"
using namespace tes;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew Form1());
return 0;
}
//form.h
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
test1 ^t1 = gcnew test1;
test2 ^t2 = gcnew test2;
test3 ^t3 = gcnew test3;
}
|
|
|
|
|
Well the point is not make so many level namespace, but I create so many file for same namespace (I a little bit confuse if see so many class/source code lines in one file). But if i copy paste the namespace then i must do it for 10 times if i create 10 file (I usually use add class wizard, it easiest way creating class).
Have you use Visual C#, in the project properties, application tab, it have a field that said "Default Namespace", if we set it for example "NSA.NSB", then when we add a class using the Diagram or Add Class Wizard the file automatically add code "namespace NSA.NSB".
For example we add a class called Test using the wizard, then we will have file named Test.cs and the code inside it (we have set the default namespace first, and it called "NSA.NSB") :
namespace NSA.NSB // <- This is auto generate by wizard by setup default namespace.
{
public class Test
{
//TODO: Class logic here.
}
}
With the code i hope you all understand what i mean.
Thanks.
|
|
|
|
|
Now i understand what you mean. The anser to your question is: You can't, not in c++. If you want to do it more quickly, then have a notepad and have your namespace ready. Create new code, copy paste from notepad and write 1 line to create class.
|
|
|
|
|
A few days ago I described a problem of Managed extensions with System.Security.Policy.PolicyException. Nishant Sivakumar suggested I try Adding Assemblies to Security Policy, which was a good idea. Unfortunately, up until now, I haven’t been able to make it fly. In this page there is a sentence “Before you add an assembly to security policy, you must give it a strong name and put it in the global assembly cache.” I haven’t exactly understood how to give my program a strong name and put it into the global assembly cache. When I tried according to the example on the same page, it didn’t work.
I see that the basic idea was sound since turning off security by “caspol –s off” made the program begin to work over the LAN. Turning off security isn’t exactly a great idea, so I turned it back on again.
I looked at the neighboring pages and it talks about reasonable things like System.Data.SqlClient.SqlClientPermission, which I in fact use. It doesn’t list individual programs, like I have built.
I decided to do an experiment. I took another program which I wrote, which doesn’t use managed extensions and tried to run it from the same “temp” directory, which I shared as z:\temp. It worked both from the local disk, temp, and from the LAN z:\temp. I then recompiled it using Managed Extensions. Clearly it was using absolutely nothing from managed extensions, but was just compiled using the option. Now it worked on the local computer but failed the same way on the LAN.
This implies that EVERY program which uses managed extensions in even the most trivial way will have problems. This seems to me to be absolutely crazy. How can anyone get any work done? There has to be a more general solution. Maybe it is a problem of version numbers between my Visual Studio 2003 and my latest version of XP?
Any suggestions would be welcome.
Thanks,
Ilan
|
|
|
|
|
IlanTal wrote: Turning off security isn’t exactly a great idea, so I turned it back on again
Good, turning off the security is a really bad idea.
Why do you want to run it from the LAN?
If you try and update the binaries and a user has them launched from the network you won’t be able to. Consider the advice from my previous post.
Your Network admins will thank you...
|
|
|
|
|
Turning off security was just a method to prove where the problem is.
I already bought your idea from the previous post. When you suggested it for the compiled help, I immediately realized it would work here as well.
The original idea of running from the network was to guarantee that all users are using the same software, but the intelligent download works just as well (or even better from a bandwidth point of view).
|
|
|
|
|
IlanTal wrote: I already bought your idea from the previous post. When you suggested it for the compiled help, I immediately realized it would work here as well.
Simplicity.
|
|
|
|
|
IlanTal wrote: This implies that EVERY program which uses managed extensions in even the most trivial way will have problems. This seems to me to be absolutely crazy. How can anyone get any work done? There has to be a more general solution. Maybe it is a problem of version numbers between my Visual Studio 2003 and my latest version of XP?
I believe this is part of the .NET security model. Dig into that, in the end you will find it more preferable to deploy locally.
|
|
|
|