|
Have you an example of API Windows with use BYTE*?
Because I use API Viewer 2003 and I can compare the sintax.
Alexsander "Axia" Antunes
|
|
|
|
|
I asked somthing like this the other day, heres what Heath Stewert told me:
>Instead of passing byte* as the parameter, declare your parameter using either ref or out
>for value types (like a Byte). This is the most common method.
>
>For instance, if the C functions is declared like so:void SomeFunc(byte* b);
>...declare your method like so:[DllImport("...")]private static extern void SomeFunc(ref byte b);
>Microsoft MVP, Visual C#
>My Articles
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
OK!
<br />
[DllImport("fplib.dll", EntryPoint="FPMGetImage", <br />
SetLastError=true, <br />
CharSet=CharSet.Ansi, <br />
ExactSpelling=true,<br />
CallingConvention=CallingConvention.StdCall)]<br />
public static extern int FPMGetImage([In, Out] byte[] buffer);<br />
This code run perfectly! THANKS FOR ALL!!
Matthew Hazlett wrote:
I asked somthing like this the other day, heres what Heath Stewert told me:
>Instead of passing byte* as the parameter, declare your parameter using either ref or out
>for value types (like a Byte). This is the most common method.
>
>For instance, if the C functions is declared like so:void SomeFunc(byte* b);
>...declare your method like so:[DllImport("...")]private static extern void SomeFunc(ref byte b);
>Microsoft MVP, Visual C#
>My Articles
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
Alexsander "Axia" Antunes
|
|
|
|
|
I have a generic "value" object as a property within a class which can then be later filled from either columns from a DataReader (retrieving) or from a text box, scrollbar or other input control (restoring).
Later on the data is compared with another property which is defined on class construction, a System.Type. So this is basically acting as a datatype constraint: I intend for it to produce an error if the type of "value" does not match the constraint.
Now here's the problem, I can't find a way to create a dynamic type-cast, or a comparison with "is"/"as". Any ideas?
|
|
|
|
|
for dynamic casting use Convert.ToType(oject, dynamicobject.Type.BaseType)
where dynamicobject.Type.BaseType (or a similar expression ) would give you the base type of the object that you have. - i hope this is what you are looking at.
|
|
|
|
|
|
HAHAHA_NEXT wrote:
Use the typeof operator
Not much use with casting...
top secret
|
|
|
|
|
Sorry my error. Did not see, the fact that hee needed to type case the object after verifiing that it was of teh good type.
|
|
|
|
|
Is there a difference between MyMethod1() and MyMethod2() ? First method doesn't use this , second method does use it. Same thing in constructor:
public class MyClass
{
int i1, i2;
MyClass()
{
i1 = 10;
this.i2 = 20;
}
int MyMethod1()
{
int iRet = i1 + i2;
return iRet;
}
int MyMethod2()
{
int iRet = this.i1 + this.i2;
return iRet;
}
}
Regards, mYkel
|
|
|
|
|
|
To explain why RNEELY simple answered "no", it's because the compiler assumes that any un-qualified calls use the this reference anyway. It's an implicit object. When it compiles, the exact same Intermediate Language (IL, the language embedded in modules of which an assembly is partly comprised) is produced. In both cases, the optimized body of each method would look something like this:
ldfld int32 MyClass::i1
ldfld int32 MyClass::i2
add
ret
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Okay... Here's a question for you...
[Edit]
Ooops! The original version of this program had an error in it that I didn't intend. Here is the correction, the multiple choice answers were as before.
[/Edit]
What is the output of this program:
01: class App
02: {
03: int i1 = 0;
04: int i2 = 0;
05:
06: public void Method1()
07: {
08: i1 = 2;
09: i2 = 3;
10: }
11:
12: public void Method2(int i2)
13: {
14: i1 = i2;
15: }
16:
17: public static void Main()
18: {
19: App a = new App();
20: a.Go();
21: }
22:
23: public void Go()
24: {
25: Console.WriteLine("i1 = {0}, i2 = {1}", i1, i2);
26: Method1();
27: Console.WriteLine("i1 = {0}, i2 = {1}", i1, i2);
28: Method2(5);
29: Console.WriteLine("i1 = {0}, i2 = {1}", i1, i2);
30: }
31: }
Is it:
a)
i1 = 0, i2 = 0
i1 = 2, i2 = 3
i1 = 3, i2 = 3
b)
i1 = 0, i2 = 0
i1 = 2, i2 = 3
i1 = 5, i2 = 3
c)
i1 = 0, i2 = 0
i1 = 2, i2 = 3
i1 = 5, i2 = 5
d)
None of the above - it generates a compiler error on line 12
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
boogs guesses c) -> arguments take precedence over members.
and no, i didn't test it - that would be cheating
|
|
|
|
|
d0h, it was b). for the same reason.
|
|
|
|
|
E) None of the above
The signature for Main is an invalid one for an entry point. Also, changing it to static would preclude Main from accessing the public members of the App class without first creating an instance of the class.
RageInTheMachine9532
|
|
|
|
|
Okay - let's assume I didn't make that error...
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
You know, this keyword is mostly used whenever in a function, the passed in parameter has a name the same as the name of a field:
private string name;
public void SetName(string name)
{
this.name = name;
}
Don't forget, that's Persian Gulf not Arabian gulf!
Murphy: Click Here![^] I'm thirsty like sun, more landless than wind...
|
|
|
|
|
Thanks for your comment... what you say makes totally sense!
OT: You should check the link to the murphy page in your signature it's not "http://www.thecodeproject.com/..." but "http://www.codeproject.com/...". Glad I could help you too
Regards, mYkel
|
|
|
|
|
It's really pleasure that it made sense!;)
BTW, thanks for notification about signature
Don't forget, that's Persian Gulf not Arabian gulf!
Murphy: Click Here![^] I'm thirsty like sun, more landless than wind...
|
|
|
|
|
Hello,
I am wondering if there is a way to programatically find a code group in the configuration wizard?
Basically, I have a c# app (local) that calls c# apps (remote share). If I try to call an app without the proper permissions set up, the CALLED app seems to throw a security exception. Since I have no idea how to trap an exception in localApp that is thrown by calledApp, I want to try something else:
What I want to do is this:
1) Before calling remote app, somehow query the Machine Code Groups in .NET Framework Configuration (programatically).
2) If the required code group does not exist, create it.
3) Finally, call the remote app.
Is this possible?
Thanks,
Ian
|
|
|
|
|
Yes, you can enumerate the code groups. You can enumerate the SecurityManager.PolicyHierarchy to get the right policy (like Machine), then enumerate the code groups underneath that. I do it in are installer for our touchless-deployment app (well, not completely touchless since a one-time installation is required). You can further add code groups using this mechanism, but you should at least prompt the user. Companies and savvy users don't like you messing with security unless it's clear that you are and why you are messing with security.
Really, though - if both of these applications are managed applications, you should consider another approach. If you don't mind that one "process" runs within the first, you can create a new managed AppDomain and load the assembly that contains the entry point Main from the second application using AppDomain.ExecuteAssembly . You can either pass your current AppDomain 's evidence, or gather host and assembly evidence for the new AppDomain and pass that to ExecuteAssembly . If the executable does not have the necessary permissions, a SecurityException is thrown at that time.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath -
I hate to ask but given that I am a total noob at this - can you provide (or point me to) a more specific example of enumerating the PolicyHierarchy and searching for specific groups? I am unable to actually resolve specific group names or at least cannot figure out how to.
Right now I have:
IEnumerator levels = SecurityManager.PolicyHierarchy();
while(levels.MoveNext())
{
PolicyLevel pl = (PolicyLevel)levels.Current;
Console.WriteLine("Policy Level: {0}", pl.Label);
}
Which prints:
Policy Level: Enterprise
Policy Level: Machine
Policy Level: User
I see a method in there called ResolveMatchingCodeGroups() but it wants an "evidence" and no matter what I try in the Evidence object it always returns the same things, something like:
All_Code
All_Code
All_Code
I want to check if "MyCustomCodeGroup" exists. It is located here:
- Runtime Security Policy
- Machine
- Code Groups
- All_Code
- LocalIntranet_Zone
- MyCustomCodeGroup
The membership condition type is "URL" and the URL is "file://MyServer/*".
The permission set on this group is FullTrust.
As for the other part of your reply - The appdomain/assembly stuff is complete greek to me. I will have to learn more about it. However I would say that the local exe calls remote exe's. The remote exe's can be managed code but also they can be .cmd/.bat files or even .msi, or .exe (C++ apps).
Thanks for your help,
Ian
|
|
|
|
|
Ahh I figured it out finally
|
|
|
|
|
The important thing is not the name of the code group, but that the permission set assigned to the code group is sufficient to run your code. What if someone changed the name of the code group or created their own? It's the CodeGroup.PolicyStatement - or rather the PermissionSet that the PolicyStatement contains - that is important.
Instead of checking that, though - as there would be much more to do - you could get the evidence for your new assembly and compare that against the CodeGroup.MembershipCondition to see if they match.
As far as launching any executables besides .NET assemblies, code access security doesn't really matter except for the ability to access that file on whatever media it resides. Your application that launches that application must have permissions to access that resource (read access, in order to launch it). It is your application that must have it, so if you want to determine whether or not you can before you launch it, you should create a FileIOPermission with the path to the resource and in a try/catch call Assert . If no exception is thrown, you can go ahead and launch the executable. Catch any SecurityException that is thrown and display and error, log it, or whatever.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks again,
I think I have this working to my satisfaction (for the time being at least - till I figure out more of how all this works).
What I do is enumerate down to the groups below LocalIntranet_Zone and look for MyCustomAccess. Then I also check that it is type URL and points to the appropriate share location. I also check that it has FullTrust permission set.
Here's my next problem:
If I do NOT find the proper code group with proper permissions, I want to add one. I have seen many examples in various places. Every example creates a new code group at the same level as LocalIntranet_Zone (siblings(?)). I want to create a new group that is a child of LocalIntranet_Zone. While I haven't keyed in the examples, I assume they work. The issue I have is when I call SecurityManager.SavePolicy() - it does not actually get saved, even though the group was added or at least seems to have been added.
Here is my code: can you tell me what is wrong? Why doesn't it save?
<br />
static bool addCodeGroup() <br />
{<br />
<br />
IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();<br />
<br />
while (policyEnumerator.MoveNext()) <br />
{ <br />
<br />
PolicyLevel machineLevel = (PolicyLevel)policyEnumerator.Current;<br />
<br />
if (machineLevel.Label == "Machine") <br />
{<br />
IEnumerator ie_MachineLevelGroups = machineLevel.RootCodeGroup.Children.GetEnumerator();<br />
<br />
while (ie_MachineLevelGroups.MoveNext()) <br />
{<br />
<br />
CodeGroup machineLevelGroup = (CodeGroup)ie_MachineLevelGroups.Current;<br />
<br />
if (machineLevelGroup.Name == "LocalIntranet_Zone") <br />
{<br />
<br />
PermissionSet permSet1 = new NamedPermissionSet("FullTrust");<br />
IMembershipCondition membership1 = new UrlMembershipCondition("file://wstltest/*");<br />
PolicyStatement policy1 = new PolicyStatement(permSet1);<br />
CodeGroup codeGroup1 = new UnionCodeGroup(membership1, policy1);<br />
codeGroup1.Name = "WSTLTEST_ACCESS";<br />
machineLevelGroup.AddChild(codeGroup1);<br />
SecurityManager.SavePolicy();<br />
<br />
<br />
}
<br />
}
<br />
}
<br />
<br />
}
<br />
<br />
return true;<br />
<br />
}
|
|
|
|
|