When the explorer detached the dll which is for shell namespace extension on win Xp? - dll

I found that:
the dll was detached(process) when I close the window(opend shell namespace externsion), but sometime didn't.
There are some global object in my dll. so, I want to find out when the dll be detached(process).

If you export the DllCanUnload function from your DLL you will be called when Explorer wants to unload your DLL. You can block it if you want, or perform some clean-up before allowing the unload.

Related

"DLL caused an exception" when calling a method that references another DLL

I developed a DLL, let's call it DomainLogic.dll, with some public methods through [DllExport] annotation. Some of those methods make calls to another DLL, let's call it Utils.dll. I developed a demo WinForm application with some buttons that call methods of DomainLogic.dll and everything works as expected.
Currently we have a partner which wants to call our DomainLogic.dll from their existing Visual FoxPro application.
They were able to successfully call dll methods that receive and return strings and open forms. However when they try to call a method that internally makes a call to another DLL (Utils.dll), a FoxPro error is displayed saying "Declare DLL call caused an exception".
SET DEFAULT TO C:\Folder\Containing\DLLs
DECLARE ExampleMethod IN DomainLogic.dll
? ExampleMethod()
Any idea how to solve/debug this?
More info:
Our DLLs require .NET 4.0, they have 4.5.2 installed.
Utils.dll is correct, I successfully called the same methods using my demo app.
We already executed the regasm /codebase command for both DLLs.
We are running the FoxPro app on the same folder as the DLLs using FoxPro's SET PATH command.

Use function of DLL in VBScript

I want to use a function of my Encryption.dll in my VBScript.
If I try to register the dll with regsvr32 /i Encryption.dll I get the error that the dll is loaded, but he can't register the file because there is no DllRegistryServer-Entrypoint.
So I tried another way as I read in a forum:
Set yourClass = CreateObject("Encryption.Hashing")
There I'm getting a ActiveX error.
Anymore ideas of what I can do?
Sounds like maybe the DLL was compiled improperly? Do you have the source? If not, try something like Telerik's JustDecompile and see if it can decompile it. This is not the end all be all kind of test but if it's a .NET dll, you should be able to decompile it. If it's a native DLL, there should be an error.
Without knowing that, there's several reasons you could be having problems.
Try creating a wrapper that exports the functions you need; test it in VS and then build it and try installing it again. Oh, one more thing. Native Libs have a .lib file that usually comes with the DLL if it's meant to be linked to for invoking purposes. That .lib and it's corresponding header files will be what you need to write a wrapper. Cheers.

COM access to VB.Net dll without strong name signing

I'm converting a VB6 dll to VB.Net using Visual Studio 2008 Express. I want to use the same .dll to integrate with Excel via Excel-DNA, but also to be available via COM (I need to be able to call it from VBScript and VBA).
If I leave the assembly unsigned, I have access to all of the ExcelDNA functionality but no COM access.
If I sign the assembly with a strong name, then when I try to build the .dll I get the following error:
Unable to emit assembly: Referenced assembly 'ExcelDna.Integration' does not have a strong name
What are my options?
You don't have to strong-name a [ComVisible] assembly. It is only required when you want to install it in the GAC. Not strictly necessary although not a bad idea to fight DLL Hell. You need to register it with Regasm.exe using the /codebase option. Visual Studio already does that automatically, although the option might be missing in the Express edition.
Fixing the second problem shouldn't be hard either. Just rebuild the Excel-DNA solution from the source code you can download from Codeplex.
Excel-DNA has an option to expose your .NET classes to COM directly, so you can use them directly from VBA as regular COM classes.
To do this your class must be ComVisible (or the whole assembly must be ComVisible), and you must mark the ExternalLibrary as ComServer='true' in the .dna file, something like:
<DnaLibrary RuntimeVersion='v4.0' />
<ExternalLibrary Path='MyAddIn.dll' ComServer='true' />
</DnaLibrary>
Then you have some options for registration:
either call "Regsvr32.exe MyAddInDna.xll"
or in the AutoOpen of your add-in, call ExcelDna.Integration.ComServer.RegisterServer()
Both of these set the registry entries so that the .xll file becomes the COM server for your classes. You can then access them late-bound from VBA, with CreateObject("MyNameSpace.MyClass").
You need another step to set up a type library (to give you intellisense in VBA). For this you generate the type library with tlbexp.exe. The regsvr32 / ComServer.RegisterServer call will find the type library and register it too.
You can also pack the .dll into your .xll file (adding a pack='true' attribute to the ExternalLibrary tag) and the type library will also be packed if present, and registered from the resource in the .xll file when you call Regsvr32.exe
So the end result could be a single file .xll add-in that is both an Excel Add-In with UDFs, ribbons, RTD servers and also a COM server that you can access from VBA.
More info in the discussions here: http://exceldna.codeplex.com/discussions/252721 and here: http://groups.google.com/group/exceldna/browse_frm/thread/4c5a71efbe96d885.

registering .net assembly as com

I have a C# class library which calls a native code DLL. I am trying to call this code from VBA.
I configured MSVC to register the generated DL and it works fine. I can access objects in DLL and work with them without any problem.
I want to register them in another computer and I am using the following command:
%windir%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /tlb /v MyNetAssembly.DLL
The command return successfully but when I am trying to use the dll objects in VBA, I am getting error file not found (80070002). I tried to add path to the place that dll resides, copy the dlls to windows directory, using /codebase option, without any success.
What is the problem and how can I solve it?

Avoid Other applications load my dll

I have created a ContextMenu DLL (to dispaly icon overlay and other shell context menus) and register it in my system.
Acutally, since it is a context menu dll, I wish only explorer exe should load my dll. But in my case, applications like 'Thunderbird', 'Process Explorer', 'Visual studio', ... etc are all using my dll.
Is there any way to avoid other applications using my dll. I only want explorer exe to load my dll. Is there a way to check this in my dll ???
Thanks in Advance.
In DllMain you can test the name of exe file which loaded your dll with respoct of GetModuleFileName with NULL as the firts parameter. If a wrong exe try to load your dll the DllMain can return FALSE.