|
Hi All,
While learning unmanaged code i got few questions Please if anyone knows please let me know.
1. If i have unmanaged code like C or C++ in my C# application then who is going to compile this code ?
2. Can we have intermediate Language (MSIL) for unsafe code?
3. What compiler will do when we make true for "Allow unsafe code" setting in build option of configuration.
4. Which languages comes under unmanaged code ?
I gone through many articles on Web but couldn't got answer for these questions
modified on Tuesday, November 4, 2008 1:43 AM
|
|
|
|
|
Member 4554649 wrote: 1. If i have unmanaged code like C or C++ in my C# application then who is going to compile this code ?
You cannot have mixed languages in the same project. So, yes, you can have a C# project and a C++ project in the same solution. Seperate compilers would have to compile each project, depending on the language used in that project.
Member 4554649 wrote: 2. Can we have intermediate Language (MSIL) for unsafe code?
The question doesn't make sense. All managed code (C#, VB.NET, C++ CLI, ...) is compiled to MSIL, so yes, in all cases, you have MSIL code in unsafe code blocks. But, I don't think that's what you're asking.
Member 4554649 wrote: 3. What compiler will do when we make true for "Allow unsafe code" setting in build option of configuration.
This makes me wonder if you know what "unsafe" code is. An unsafe code block is just a block of code that uses pointers. Since pointer math and types cannot be verified safe at runtime, it's called unsafe code. The Unsafe keyword just tells the compiler that this section of code cannot be verified type safe, so it needs to relax it rules a bit in this section in order to successfully compile the code.
|
|
|
|
|
Thanks Dave,
Actually i got confused in Unmanaged and unsafe code.
Now things are clear in my mind but one thing that needs to be addressed
Unmanaged code means All languages like C,C++,Win API, VC++,VB 6
i.e languages which produces Native code when compiled for windows OS
Is it right ?
One more thing if in my application i have unmanaged code who is going to compile that code ?
|
|
|
|
|
Member 4554649 wrote: Unmanaged code means All languages like C,C++,Win API, VC++,VB 6
Yes, but...there are managed variants of c++ (called c++\cli). The Win API is a framework not a language. It is an unmanaged framework, but it can be called from either managed or unmanaged code. VB6 actually has the option to be compiled as unmanaged or managed code (called P-code in the case of VB6). It's int the project settings somewhere IIRC.
Unmanaged is anything that is compiled straight to machine code and runs directly on the system. Managed means it is compiled to an intermediate language (MSIL for c#, bytecode for Java, etc), and a runtime (like the CLR or JVM) is used to interpret that intermediate language and convert it to machine code as the program is running - This is called JIT compilation (Just In Time).
Member 4554649 wrote: One more thing if in my application i have unmanaged code who is going to compile that code ?
The compiler. GCC for c++ or the visual studio IDE for vc++. You can't mix managed and unmanaged code in the same project.
Simon
|
|
|
|
|
Hi all,
I have created an Excel 2003 AddIn project and created one Setup project also for install the AddIns in target machines. My setup contains the primary out put of the AddIn project. I just came to know some registery entries are required for successful installation. Can any one help me in creating setup project with necessary registery entries.
|
|
|
|
|
Stop cross posting.
Pick 1 forum most related to your question, and ask your question there, and only there. People won't help you any faster if you just post everywhere.
Post 1[^]
Post 2[^]
Post 3[^]
Post 4[^]
Simon
|
|
|
|
|
Hi,
In VS 2005 I am using Reflection to parse .Net System libraries. Using GetMembers(BindingFlags) returns some additional methods other what is defined in the interface/class in .Net system library. For filtering out I am using following BindingFlags combination
BindingFlags::Public | BindingFlags::Instance | BindingFlags::Static | BindingFlags::DeclaredOnly
I am trying to get the declared members in class/interface say for example System.Collection.ICollection which has following 4 members:
int Count { get; }
bool IsSynchronized { get; }
object SyncRoot { get; }
void CopyTo(Array array, int index);
However using GetMembers I get following 7 members:
int Count { get; }
bool IsSynchronized { get; }
object SyncRoot { get; }
void CopyTo(Array array, int index);
int get_Count();
bool get_IsSynchronized();
object get_SyncRoot()
I get extra 3 get methods corresponding to each property. How do I suppress or filter out these additional members?
~Manish
|
|
|
|
|
A property is just a declaration which specifies the get and set methods.
Either use GetMethods or take a look at the MemberInfo, theres a whole bunch of info exposed there that you can use for filtering.
|
|
|
|
|
Hi there
I would like to be able to stop all text in a ComboBox from being automatically selected when I tab into a it (it has DropDownStyle of DropDown).
Currently, I check for KeyUp event, and select the text I want to select, rather than the whole lot. This still has the effect of all text being selected temporarily until the tab key is released. Is there any way to suppress the SelectAll behaviour?
Thanks in advance
Paul
One day I want to be a code monkey. Right now, I'm more like a code amoeba...
|
|
|
|
|
Instead of using KeyUp, try wiring Enter or GotFocus event and deselecting the text.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Thanks Mika, GotFocus solved it. Enter occurs before the SelectAll, otherwise I would have used that. Never knew about GotFocus though, so awesome result!
Cheers
Paul
One day I want to be a code monkey. Right now, I'm more like a code amoeba...
|
|
|
|
|
You're welcome
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Hello,
I am developing a client and server application for bluetooth devoce. My server is desktop PC which has dongle attached and client will be Windows Mobile. As client server get connected server will send to client list of some files. from the client side i should be able to download file means copying file from server to client. I am using sockes for eastablise connections. Now i have to send a file from server to client. How can i send a file? Please help me.
Thanks and regards,
Yudhisthira attry(India, Bangalore)
|
|
|
|
|
|
Hi,
i want to show the windows File Association form when user presses a button. I use the following code:
Imports System.Runtime.InteropServices
Public Declare Auto Function OpenWithDialog Lib "shell32.dll" Alias "OpenAs_RunDLL" (ByVal hwnd As IntPtr, ByVal hinst As IntPtr, ByVal lpFile As String, ByVal nShowCmd As Int32) As Int32
Private Sub button_ItemClick(...)
OpenWithDialog(Me.Handle, Marshal.GetHINSTANCE(Me.GetType().Module), "", CInt(AppWinStyle.NormalFocus))
End Sub
Well, it opens a similar form, the "Open With..." form, but i am not looking for the Open With... form. I imagine that i have to make 1-2 changes and after that then it will really open the File Association form(Set Association - Associate a file type or protocol with a specific program).
Any idea what i need to change on this so it work?
Thanks in advance
|
|
|
|
|
|
Hi all..
I need to change a class inheritance at runtime. Specifically I need to change the Control class to inherit from a MyControl class instead of the Component class.
I've been searching for ways to do this. I come across with Reflection.Emit, Profiling API, some code injection tools, but I am still very confused on how to do this. Is there any other way to do this?
Has anyone here have tried to do something similar? If so what techniques have you used?
Thanks,
José Tavares
|
|
|
|
|
In this instance, you can't change the inheritance chain. To do this, would require you to implement the features that the class is relying on from the base class. There are cases where you can appear tochange the inheritance chain, but this behaviour has to be coded in from the start. When you think about it, from a security standpoint, it would be a bad idea to change the behaviour because you could change the implementation to inherit from insecure/dangerous code, and would you really want this if you were a user?
|
|
|
|
|
I understand that and had thought about it already but it would be very helpful for me
Another hypothesis is to change the assembly to reflect this change. Can I change the System.Windows.Forms assembly with this changes (injecting the class into the assembly). If I use this assembly in the directory of the application would the compiler try to load it before it goes to GAC?
I've come across with an application RAIL (http://rail.dei.uc.pt) but it's no longer supported. Do you know any similar tool that allows me to change an assembly?
Thanks,
José Tavares
|
|
|
|
|
The only thing I can think of would be mono.cecil. It might help, but I haven't done enough with it to be sure.
|
|
|
|
|
I gave Mono.Cecil a try and was able to change the BaseType of Control to MyControl instead of Component.
The problem now is that I do not want to replace the System.Windows.Forms.dll in the GAC. I would like to use the new dll in the bin directory of my application. But it seems to be always loading the one in the GAC. Is this somehow possible?
|
|
|
|
|
jpsstavares wrote: I need to change a class inheritance at runtime.
Maybe you do and maybe you don't. Since you did not provide requirements I can only doubt your conclusion. It is far more likely that you need a different design.
led mike
|
|
|
|
|
You're right I forgot to mention that.
I'm doing a test suite to test application's GUIs and one problem to do this is the identification of components. You may have Controls with the same name, with the same automation ID, so there is no unique identifier to a Component that identifies it over different executions and different versions of the software.
The idea is to add an ID to the Control class that would automatically be created and that would allow me to identify controls (I want to add other things but this is my main reason).
Thanks
|
|
|
|
|
jpsstavares wrote: I'm doing a test suite to test application's GUIs
Ok, that explains a lot. Good luck, way outside my area of knowledge.
led mike
|
|
|
|
|
Hi,
Controls have a Tag property that normally is not used at all (by the Control
itself), i.e. it is reserved for the user, so he can attach an object of his
choice. Maybe that is sufficient to solve your identification problem?
|
|
|
|