|
If I write a pure C# application, only using the standart publi API, no interop, the same binary should work well on32 bit, 64 bits and perhaps on the compact framework as well if I link against it.
Now how could I achieve the same thing if I do interop and I have a managed C++ API?
let say I have a managed C++ module compiled for 3 different target but with always the same interface:
mycppmodule32.dll
mycppmodule64.dll
mycppmoduleCE.dll
let say in the C# code I also do some interop
internal class User32 // & CE ?!
{
[DllImport("USER32")]
public IntPtr GetHdc(IntPtr hWnd); // 4 byte IntPtr
}
internal class User64 // not sure it exists, but I assume....
{
[DllImport("USER64")]
public IntPtr GetHdc(IntPtr hWnd); // 8 byte IntPtr
}
Let suppose these DLLs are included as modules in my csharpdll.dll.
Now if I deploy all these DLLs, how could write a simple nice code in my C# dll which internally target whatever native lib is appropriate?
Is it possible (to keep it simple)?
|
|
|
|
|
I am new to C# and .Net. I am trying to execute a bat file from inside a C# application. I continue to get a security error and no one here can help me out. Any ideas?
Thanks in advance.
tom
|
|
|
|
|
Don't cross post for a start. You've already had several replies, mine included.
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
|
|
|
|
|
Well. I was told here that this may be a .net security issue.
Here is my error message:
Unhandled Exception: System.Security.SecurityException: Request failed.
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly a
sm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, Secur
ityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object ass
emblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle
rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet gran
ts, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Objec
t assemblyOrString, SecurityAction action, Boolean throwException)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs
, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMet
hodHandle rmh, Assembly asm, SecurityAction action)
at ConsoleApplication_uisftp.HelloWorld.Main()
The action that failed was:
LinkDemand
The type of the first permission that failed was:
System.Security.PermissionSet
The demand was for:
<permissionset class="System.Security.PermissionSet"
version="1"
unrestricted="true">
The granted set of the failing assembly was:
<permissionset class="System.Security.PermissionSet"
version="1">
<ipermission class="System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
read="USERNAME">
<ipermission class="System.Security.Permissions.FileDialogPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
unrestricted="true">
<ipermission class="System.Security.Permissions.FileIOPermission, mscorlib, Vers
ion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
read="R:\C#2\ConsoleApplication uisftp\ConsoleApplication uisftp\bin\Debug\"
pathdiscovery="R:\C#2\ConsoleApplication uisftp\ConsoleApplication uisftp\bin\De
bug\">
<ipermission class="System.Security.Permissions.IsolatedStorageFilePermission, m
scorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
allowed="AssemblyIsolationByUser"
userquota="9223372036854775807"
expiry="9223372036854775807"
permanent="True">
<ipermission class="System.Security.Permissions.ReflectionPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
flags="ReflectionEmit">
<ipermission class="System.Security.Permissions.SecurityPermission, mscorlib, Ve
rsion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
flags="Assertion, Execution, BindingRedirects">
<ipermission class="System.Security.Permissions.UIPermission, mscorlib, Version=
2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
unrestricted="true">
<ipermission class="System.Security.Permissions.UrlIdentityPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
url="file:///R:/C#2/ConsoleApplication uisftp/ConsoleApplication uisftp/bin/Debu
g/ConsoleApplication uisftp.exe">
<ipermission class="System.Security.Permissions.ZoneIdentityPermission, mscorlib
, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
zone="Intranet">
<ipermission class="System.Net.DnsPermission, System, Version=2.0.0.0, Culture=n
eutral, PublicKeyToken=b77a5c561934e089"
version="1"
unrestricted="true">
<ipermission class="System.Drawing.Printing.PrintingPermission, System.Drawing,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
version="1"
level="DefaultPrinting">
The assembly or AppDomain that failed was:
ConsoleApplication uisftp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The Zone of the assembly that failed was:
Intranet
The Url of the assembly that failed was:
file:///R:/C#2/ConsoleApplication uisftp/ConsoleApplication uisftp/bin/Debug/Con
soleApplication uisftp.exe
Press any key to continue . . .
|
|
|
|
|
For a start try running it under an admin account if you can, if that succeeds then it's your permissions that are at fault. Otherwise it's something else which I'm not sure of without looking it up.
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
|
|
|
|
|
Simple Question: Is it possible to restart the .NET framework to simulate a “cold start?” (I.E. similar to restarting your computer and inheritly the framework without restarting your computer.)
If this is possible, how does one accomplish this?
Thank you,
Frank V.
www.TheOpenSourceU.com
|
|
|
|
|
You can't. The Framework is only a set of DLL.
My Blog
|
|
|
|
|
I think that you are correct. You can't. But the framework is more than just DLLs. There is an engine that runs to compile these apps. The 'DLLs' are loaded in to memory (by the engine) and then used through the use of the session. (Until the computer turns off).
I'm looking to unload all of the dlls from memory. And again, I think you are right. you simply cant without restarting and flushing the memory...
Thanks for your response!
Frank V.
http://www.TheOpenSourceU.com
|
|
|
|
|
The .NET framework exists in any process which is running managed code. "Restarting" the framework basically means killing the process and rerunning the managed app.
Josh
|
|
|
|
|
Stop all managed Apps & restart any one of them!
|
|
|
|
|
Why do you want to "cold start .NET Framework"?
Best,
Jun
|
|
|
|
|
I need to simulte a fresh boot cycle (and am trying to save time) so that I can test performance of an application that will only be ran once the computer starts up. Hence, inital load time is important.
Thank you,
Frank V.
|
|
|
|
|
Jawz-X wrote: I need to simulte a fresh boot cycle
An interesting idea, but I am not aware of any such approaches.
Best,
Jun
|
|
|
|
|
Hi,
How would you add a reference to microsoft.xml namespace?? I tried using imports and it comes back with
imports microsoft.visual basic - not giving XML choice?
Many thanks.
|
|
|
|
|
There is no Microsoft.Xml namespace, it's System.Xml.
You have to add a reference to the .DLL file that the namespace resides in. In the Solution Explorer, right-click the References folder, then click on Add Reference. In the dialog that comes up, make sure the .NET tab is selected, then scroll down the list and find System.Xml. Double click it and you've added the reference to your project. Then you can add
Imports System.Xml
at the top of your code.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
When trying to write to the windows application log the following (vb.net code) works great on 2000 and XP but not on Vista:
Dim ev As New EventLog("Application", System.Environment.MachineName, "MyProgramName")
Dim LogText As String = "Hello world"
Dim EntryType As System.Diagnostics.EventLogEntryType = EventLogEntryType.Information
ev.WriteEntry(LogText, EntryType, LogEventID)
ev.Close()
What happens is the following excpetion is thrown on Vista:
System.Security.SecurityException: The source was not found, but some or
all event logs could not be searched. Inaccessible logs: Security.
at System.Diagnostics.EventLog.FindSourceRegistration(String source,
String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String
machineName)
at System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName,
String currentMachineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID)
Can anyone offer any ideas on what extra is needed for Vista?
Thanks very much in advance for your help,
Rob
|
|
|
|
|
|
Thank you - that turned out to be the problem, however ...
When I tried to create the "source" in Vista I got another error:
"The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security."
I got around this by changing the compatibility properties on my exe file to give it Administrator rights.
However, this in turn led to a pesky Vista warning pop-up box each time my program started up.
Next I deleted the source and then tried to create it in my program by writing the reg key entry myself.
Dim Reg As Microsoft.Win32.Registry
Dim RegKey As Microsoft.Win32.RegistryKey
RegKey = Reg.LocalMachine.CreateSubKey("SYSTEM\CurrentControlSet\Services\EventLog\Application")
RegKey.SetValue("MyProgramName", "")
RegKey.Close()
I found that if I did it this way, and on the exe file removed the admin rights and changed the properties - security - users - advanced - users - edit - to full control
then everything worked ok and I didn't get the pesky Vista warnings every time I started the program.
Any advice on the advisability of one approach over the other?
Thanks, Rob
|
|
|
|
|
|
Thanks for this, but wow is it ever complicated ...
Do you know of an example somewhere where I might be able to better see how these pieces fit together - honestly after reading thru the write ups linked above and (unsuccessfully trying a few things in my code) I am more lost then when I begun.
Also, although I want access to write event log entries, I also need registry access to apply a hook into IE (that will let my clients dial a phone number right out of IE).
All this seems to work if I simply update the permissions on Vista to allow full access; I understand where it would be good to further limit these so any further support - and patience you can extend would be great.
Again, maybe a pointer to an example ....
Best Regards
Rob
www.callclerk.com
|
|
|
|
|
Rob,
Well It looks like bad news so far, you may be SOL for awhile, at least until a little more information starts comming out of MS.
I visited the winfx (vista) site and located the sample code for the registry settings called "RegistrySettingsProvider Sample" and right in the middle of the page is this BIG warning:
'--------------
Caution
This provider uses assembly metadata, such as product name, to determine a workable registry path in which to store settings. These are not secure metadata elements; they are reasonably safe from collision, but not at all safe from malicious tampering. A robust implementation of the provider, meant for use in a production environment, should improve upon this pathing algorithm.
Security Note
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
'--------------
So whoever posted that code at MS must be having the same problem, Not knowing how the security works.
Here is a link to the page, but the "security" part of the code doesn't exist, I downloaded it and checked it out.
http://windowssdk.msdn.microsoft.com/en-us/library/ms181001.aspx[^]
I guess at this point in time, and with it being a "beta" and all, your best bet is to run your code at administrative level until some more security information comes along.
I wish I had better news, and could help a bit more,
progload
|
|
|
|
|
Hello all
I was wondering if anyone out there knows of a way to filter out rows based on a condition that is more efficient than the dataview.rowfilter?
<br />
Public Sub filterDataSource(ByVal filter As String)<br />
Dim tempSelectedValue As Object<br />
If IsNothing(Me.SelectedValue) = True Then<br />
tempSelectedValue = "-1"<br />
Else<br />
tempSelectedValue = Me.SelectedValue<br />
End If<br />
Me.mDataViewCombo.RowFilter = filter<br />
Try<br />
Me.SelectedValue = tempSelectedValue<br />
Catch ex As Exception<br />
End Try<br />
End Sub<br />
The "Me.mDataViewCombo.RowFilter = filter" takes about 2 seconds to complete when there are about 700 rows and I was wondering if there was any other way to improve upon that. I have tried to "Me.mDataViewCombo.table.select(filter)", but this method does not seem to filter anything at all. Thank you.
eatwork
|
|
|
|
|
The Select function returns an array of DataRow objects. Thus the DataView isn't affected. There is no real way to improve the RowFilter performance generally. But if I recall right you might get better results if you sort the DataView by the column you are filtering (if it is a simple expression with only one column) because it then uses some kind of internal index.
|
|
|
|
|
Hi Robert,
Thank you for the post and the information. I guess I am stuck with what I got. Thanks again.
eatwork
|
|
|
|
|
The only way to improve upon this is to not have 700 rows in your DataSet. You could requery the database for the smaller rowset, but that involves bugging the SQL Server again and transferring that data over the network again.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|