Multiple dll copies of add-in loaded by PowerPoint?

Add-in Express™ Support Service
That's what is more important than anything else

Multiple dll copies of add-in loaded by PowerPoint?
Weird or is it normal for ADX addins? 
Fernando Madruga




Posts: 60
Joined: 2006-01-04

I just noticed, while tracking a different bug, that my PowerPoint add-in shows up twice in the list of PowerPoint DLLs: I have several other PowerPoint add-ins and none exhibits this behavior and I certainly don't do a thing in my add-in to make that happen.

I then proceeded to create a blank excel add-in, compiled it (zero changes), registered it and fired up excel: guess what? Two copies of that DLL loaded by Excel.

Is this normal add-in behavior?

Later,
Madruga
Posted 19 Feb, 2007 21:02:44 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Madruga,

It is normal behavior of the Delphi based add-in. BTW, the code is executed only in one dll.

P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.

Posted 20 Feb, 2007 05:57:52 Top
Fernando Madruga




Posts: 60
Joined: 2006-01-04

Thank you for the info. This could explain a problem I'm having trying to use protected sections in my DLL.

Later,
Madruga
Posted 20 Feb, 2007 12:14:29 Top
Fernando Madruga




Posts: 60
Joined: 2006-01-04

One more question, though: does it *always* "use" 2 copies of the DLL? Or does that happen only under certain circumstances?

Thank you,
Madruga
Posted 20 Feb, 2007 12:15:30 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Madruga,

As far as I know a system information tool (e.g. the ProcessExplorer tool) always _shows_ 2 copies of the dll but the code is executed only in one dll.

Posted 20 Feb, 2007 12:30:58 Top
Fernando Madruga




Posts: 60
Joined: 2006-01-04

Yes, but can you share some more info on why it shows 2? I believe that the problem I had has to do with the code being executed on the "2nd" copy instead of the 1st one. I'm not blaming you! Just trying to understand *why* those two DLL instances for the same app. What's the other one used for? Who "fires" it up? And why, on some systems they seem to be loaded in a different order?

So you can better understand the questions, even though I already decided to drop Delphi as I'm a bit fed up with fighting with a tool instead of having it help me!), here's my exact problem:

Using SoftwarePassport's exe/dll wrapper, and taking advantage of one of it's features to unprotect some parts of the code only if the user has a valid certificate, I can mark certain sections of my code such as TRIAL, LICENSED or so. The way the unprotection works is to extract as NOPs those areas for which the user does not have a valid certificate, so the code still walks through that section but executes NOPs so does nothing useful.

What I found out that was happening is that Delphi's runtime would somehow and only in some systems, relocate some global string constant references. While debugging the code, I would see, in the exact same place as such a variable address would be, something other than the NOPs that the wrapper placed there. Then I noticed the 2 DLL copies. My best guess so far is that:
1) One such DLL is not used for the code (resources only?);
2) Delphi, when executing code from a 2nd instance of the DLL will relocate the global constants/vars references;
3) Somehow, for some yet undetermined reason, those two instances get loaded in different orders, that is, in some systems, both code and data are from the same copy of the DLL, hence no relocation and no problem, and on some others, relocation is performed and I get that problem.

At this point, I'm just trying to understand the exact situation involved in having those 2 copies, as I don't believe is something related to Office because I have quite a few other add-ins and none exhibits this behavior.

Thanks,
Madruga
Posted 20 Feb, 2007 14:52:29 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Madruga,

Yes, but can you share some more info on why it shows 2?


One item is a normal dll. Another item is memory mapped sections of the dll. Let's try to look at the sections table of a dll produced by the Delphi compiler (you can use the tdump.exe tool to get similar results from your add-in dll):

==============================
Object table:
# Name VirtSize RVA PhysSize Phys off Flags
-- -------- -------- -------- -------- -------- --------
01 CODE 0001B5B4 00001000 0001B600 00000400 60000020 [CER]
02 DATA 00000968 0001D000 00000A00 0001BA00 C0000040 [IRW]
03 BSS 00000921 0001E000 00000000 0001C400 C0000000 [RW]
04 .idata 00000F06 0001F000 00001000 0001C400 C0000040 [IRW]
05 .edata 000000A6 00020000 00000200 0001D400 50000040 [IRS]
06 .reloc 000022F0 00021000 00002400 0001D600 50000040 [IRS]
07 .rsrc 00002400 00024000 00002400 0001FA00 50000040 [IRS]

Key to section flags:
C - contains code
E - executable
I - contains initialized data
R - readable
S - shareable
W - writeable
==============================

As you can see, Borland's compiler creates 3 shared sections.

MSDN quotation:
This section is shareable. When used with a DLL, the data in this section will be shared among all processes using the DLL. The default is for data sections to be nonshared, meaning that each process using a DLL gets its own copy of this section's data. In more technical terms, a shared section tells the memory manager to set the page mappings for this section such that all processes using the DLL refer to the same physical page in memory. To make a section shareable, use the SHARED attribute at link time.

For more information please see the following MSDN article:
http://msdn2.microsoft.com/en-us/library/ms809762.aspx

Hope this helps.

Posted 21 Feb, 2007 06:06:21 Top
Fernando Madruga




Posts: 60
Joined: 2006-01-04
That would explain it, but a TDUMP on my add-in dll does not show any shareable sections:

Courier

Any ideas on why this DLL is loaded twice? What of these sections/attributes is causing that and is there a command-line tool to change those?

Thanks in advance for all the help, if I can sort this one out, maybe I can keep using Delphi Win32 after all...

Later,
Madruga

EDIT: Changed CODE into FONT. CODE attribute in forum is not working OK, still shows in proportional width font...

EDIT2: Added some _ to "fix" multiple-spaces being displayed as 1 space and breaking the nice formating! :)
Posted 21 Feb, 2007 13:58:14 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Madruga,

I have no idea who and why creates a memory mapped file in your case. Please contact Borland support service regarding this question.

Posted 22 Feb, 2007 06:45:07 Top
Fernando Madruga




Posts: 60
Joined: 2006-01-04

Thanks but that would probably not yield usable results in a short time and by now I'm a bit tired of "fighting" with the IDE and thus my recent purchase of the ADX 2007 .NET so that I may try my luck on C# instead and leave Borland once and for all.

Thanks for the time spent with this,
Madruga
Posted 22 Feb, 2007 12:17:00 Top