Loading native COM DLLs in 64bit environment - c++

I have a 32bit/64bit COM DLLs in C++: mycom32.dll, mycom64.dll. Both of them are exactly the same but mycom32.dll is compiled for 32bit and mycom64.dll is compiled for 64bit.
That means that BOTH DLLs have the same UUID and the same CLSID!
Now, sometimes I want to use this COM from 32bit processes and sometimes I want to use this COM from 64bit processes.
Is it possible to load the correct DLL without creating two different CLSIDs and check during runtime if the process is 32bit/64bit?

It should be possible to register both of them without issue; this is part of what Registry Redirection is supposed to solve.
Here's a more detailed explanation of how this works.

Related

Q: Proper way to access data in a data only dll file

My application store some data in data only dll files. Those dll files are loaded with LoadLibrary() when needed at runtime and then discarded with FreeLibrary() after finish using them. The main application access the data stored in the dll files using GetProcAddress(). The program is written in C++ and uses WinAPI calls, no MFC or other libraries. It has two versions x64 and x86. It works fine on most systems. My dll files do not call other libraries or depend on anything else. Each is a stand alone file.
Recently, I discovered the program does not work on one machine. this specific one has Windows 10 x64 installed on it. After investigations I found the following:
LoadLibrary() fails with error message "Could not find module". The dll is in same directory with main program.
I replaced the call to LoadLibrary() with LoadLibraryEx() and tried the following falgs:
LOAD_IGNORE_CODE_AUTHZ_LEVEL did not work. The dll could not be loaded.
DONT_RESOLVE_DLL_REFERENCES ... works?? But, Microsoft strongly recommends not to use it.
LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE ... loading the dll succeeds?? But, the call to GetProcessAddress later fails. the program could not access the data in the dll file. So this is not actually working.
I could not find anything wrong with this machine. All other programs are working fine.
I tried the x86 version on this machine and it worked fine using original LoadLibrary().
My installer is dual system and automatically installs x64 version when it finds x64 windows. Normal user can not simply switch to x86 when he gets such error.
My question is how can I eliminate this error and make my program works on any machine:
Should I call LoadLibraryEx() using DONT_RESOLVE_DLL_REFERENCES flag and ignore Microsoft warning?
Is there any way I can get my library loaded with simple call to LoadLibrary()?
If I call LoadLibraryEx() with LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE flag, as recommended by Microsoft, how can I access the data without calling GetProcessAddress()?
Thank you in advance.

In memory load of .NET PE from native process

I did code a PE packer in C++, which does load an executable into his process space, fixes IAT and relocations, then calls the entry point.
My problem is that .NET is not supported: I did search about .NET PE format, and it is just a 32 bit executable with the entry point set to an imported function (_CorExeMain).
If I call it, windows just popups an error that tells me that I have not .NET installed.
I did also read that .NET PE executables have a special COM header in DataDirectory but I don't know how to handle it.
I hope someone could help me.
Thanks in advance
Obviously the idea you had does not work as-is for .Net.
Your "packed" executable is just a native executable whose code is an unpacker, and whose data is the compressed real executable. When running, Windows expects and gets native code.
For .Net executables, you must obviously do the same: write a .Net executable whose code is an unpacker, and whose data is the compressed .Net bytecode.

can I run binary code for arm-7 on other devices?

I have an image compiled successfully for a mobile device. I now want to run it on another device. Can I potentially use the compiled binary? I do not care about having all the functionality right now. I just want to call one of the functions in the code and get a response.
Is it possible to add the compiled code as a shared library in a JNI project?
#Alex - Thank.
Your library is built for some runtime, e.g. iOS or Linux or Windows. It cannot run on a different type of system, but usually quite easily runs on another device of the same kind.

managed dll in native code (via com) .is it in process or out process com server?

i needed to use a managed dynamic linked library(c#) in my native code(c++).i found the solution
here it was.
(http://support.microsoft.com/kb/828736).
but the thing that is bothering me is..
1) are managed dynamic linked libraries used in native code through com act as in process com servers ? . if yes how can it be?
2)if no, then how can dynamic linked library act as out process com server without being carried by an executable .
This is an in-proc configuration. It's not much more "impossible" than using P/Invoke mechanism directly. When you run regasm it makes necessary changes to the registry so that when the client calls CoCreateInstance() COM knows that it needs to P/Invoke functions from the corresponding .NET assembly.
COM knows how to start the CLR for managed DLLs, so this can work for managed DLLs that can run in the appropriate bitness (i.e., AnyCPU or 32/64 bit as appropriate).
For cross-bitness DLLs, I believe that the CLR knows how to start DllHost.exe and run the managed DLL out-of-process. It will be slower, of course.

Using 32bit .lib library in a 64bit application

I'm a starting programmer and I can't solve a problem I have now.
In MFC, I have a .lib binary file without the sources. I need to make a 64bit application that uses mentioned library file.
I thought about making 32bit console program and run one program from another, for example using IPC with WM_COPY~ (or something like that), but the .lib file needs so many attributes like array, struct, pointer, ...
Is there an easier way to use that 32bit library in my 64bit application?
Thanks
You don't have any other alternative; you cannot load a 32-bit assembly in a 64-bit program, so you'll need to create a 32 bit application that your 64 bit application can talk to somehow. There are lots of ways to do IPC, so find one that works for you.
Uhmm strange, you simply can't put a big elephant into your home fridge but you still can insert in there a big chicken. If you can't do similarly with your 32 bit lib file, tell me why any of your 32bit applications can still work in 64 bit systems ? (:D) what sort of lib is that ?