Clr dll .net control - c#

I need to dynamic loading some .NET control from DLL in runtime from C# winforms host project.
for example:
1.dll contrains control1
2.dll contrains control2
3.dll contrains control3
host app may load any of this dll-s, get controls from dll and put it on self form.
I tried:
__declspec(dllexport) TestCLRPlugin::Properties ^ GetControl()
{
return gcnew TestCLRPlugin::Properties();
}
but, clrcall methods can't be exported from dll.

You need to use the Assembly.LoadFrom methods and then you can use reflection to get the method/class/etc you want from the assembly. There are pretty good examples if you follow the MSDN link.

I'm not sure quite what you're looking for, but you may want to read up on reflection, which makes this pretty easy:
http://msdn.microsoft.com/en-us/library/ms173183(v=vs.80).aspx
Sorry if you're already familiar or that doesn't help.

Related

control a wpf from matlab by using a c# dll

i would like to know weather it is possible to control some wpf application written in c# by using a c# dll out of matlab.
what i need is the possibility to start the MainWindow and i have to be able
to get some values into my controller.
What i found so far was things working from c# that use matlab, but the other way round seems not to be that much populatet, as i found nothing i could really use.
I allready tried to import a .net Library, but i dont seem to be able to open a external class from my dll.
So if you could help me on this it would be great.
Regards,
justSomeone
Ok, i did just find out, that i can also import my .exe file into Matlab instead of only dlls .
I am using the function NET.addAssebly('Path.exe') to do this.
Path.exe is just a symbol that it is directed to the place of the .exe file.
I achieved to be able to use my methods as i wanted i do have my instance of the class. So i am happy now. :D
But if you have other solutions which are more handy, dont hesitate to post them. There might still be interesting things to discover :)
Regards,
justSomeone

Add-ons for your C# app

I have a C# program and I want to make it able to load addons. Addons are like that: You pass a control or form to it and it makes some changes to them.
Is there anyway to have dll addons and load them dynamically at runtime and pass controls??
If not Any Idea? What should I do?
Look into MEF to load and import the assemblies and the controls.
Look at Management Extensibility Framework.
Yes that's possible and it works similar to other programming languages: Load the library and call methods to get names and stuff. One possible solution can be found in this question.

Calling c# functions from an injected win32 dll

I have a win32 dll that I inject into a running process in order to extract and monitor/log data. This dll then hosts the CLR and uses ExecuteInDefaultAppDomain to load my c# dll that creates a WinForm.
Currently, when my c# dll is loaded and the init function is called, it creates a WinForm with a richtextbox to display information and it can import all my win32 dll's functions easily.
So now, how can I call a function to write to my richtextbox in my c# WinForm repeatedly(in a loop) from one of the functions in my win32 dll(both dll's are already loaded in the same process)?
edit: I have looked up quite a lot of topics relating to the various ways but none seemed to fit my situation on sites like here stackoverflow, msdn, codeguru, google.
Would using reverse p/invoke work for me in this situation? If so, can you please show me a small example?
Of course you'll use P/Invoke with a Delegate. Look at this answer here on SO: Howto implement callback interface from unmanaged DLL to .net app?

Possible to inject resource files into .net assembly?

There's a .net program for students that I've been messing around with in Reflector and Reflexil, but it doesn't look like they can work with resource files. I want to replace the default background with a custom one. How feasible is this?
I've tried exporting the assembly as a C# project and maybe rebuilding with the resource files swapped, but a few classes won't decompile right when exporting and crashes Reflector when I try to view the full source code inside reflector (after clicking 'expand methods')
What type of applicaiton is it? WinForms, WPF, Silverlight, Web? You can do it with ILDasm round triping. If you let me know what type of app it is I'll post the steps you need to take.
Reflexil 1.3 is now able to handle resources.
Quite difficult, probably Hex Editor can help.
Resource Hacker can do it. Follow; Action > Add a new Resource
delphi.icm.edu.pl/ftp/tools/ResHack.zip
I just put out GrayWolf to edit programs, I don't have the ability to edit resource(s) (if you donate$:) yet
but I would think the easy change is to edit the program to load the background from disk (./back1.jpg)
I have others tools that would make it easy to change the background of the running program see
"Hacking .NET" at DefCon18
other tools "GrayDragon"
I have a payload that does just this, it is for DefCon19, but if you send me an e-mail...
Happy hunting

Creating new C# version of existing COM object to use in Delphi program

We had a bit of a problem where we have lost some source code for a very old ActiveX component we had. We've got a Delphi7 program that calls the Active X component. Thats a bit of a moster and can't be changed too much. However, some of the functionality in the Active X component needs to be updated. Since we've been moving our apps to C#, its been decided to redo the ActiveX as a C# class library.
I've got a basic C# class library working to prove the concept. I can hack the GUIDs and registry so it just looks liek the old one. If I look at the type lib for the old one and the new one, they are basically the same. Couple of slight differences but not anything i would have thought would be a problem.
Now as far as I can see there are three ways to use the new class library:
Late binding by looking up the ProgId. This works ok.
Import the type library. (Project| Import Type Library) This works ok.
Import as an ActiveX component. This generates a tlb file. This doesn't work. When I go to create the component I get 'No such interface exists'. The class is loading to a point but not completely.
Now unfortunately, the Delphi program is using option 3. So I have to try to get my class library working in this circumstance. Any ideas how I get past that error? I googled and found some references but nothing that says what the problem is.
Second question. I should know how to do this since I've done it once but I seemed to have fluked it. When I am in Delphi I do an Import ActiveX component to generate a TLB file. Now the first C# class library generated is showing up in the list of ActiveX controls and I can Create Unit for it. But I've created another simplier class library for testign purposes and damned if I can get the library to show in the list of ActiveX controls and so I can't import it.
The Create Unit for the Active X component generates a different format of TLB.pas to the Import Type Library format and its the ActiveX one that I require.
An ActiveX Control does way more then just implementing your interfaces. It is more like an TComponent or TWinControl. It requires you to implement a lot more ActiveX Control interfaces. Your C# object exposed through COM/ActiveX is not a Control, but a simple class.
It does not show up in Import ActiveX Control since it is not an ActiveX Control. I do not think it is feasible to make your C# class an Active Control.
Another possibility, although probably not the most elegant, would be to create a new ActiveX com object in Delphi which in turn calls your C# class by either method which you already have working.
Since you stated that this is for an existing Delphi 7 application, you might want to just use Com Interop on the C# side, expose the object as com visible, and the consume it directly from your Delphi 7 application.
The first option would probably allow you to get by with minimal changes to your existing application, but does add an additional layer that most likely is not necessary.

Categories