Solved

Registering a .NET dll to use from VFP exe on WS 2012

Posted on 2015-01-28
10
382 Views
Last Modified: 2015-01-28
I am using VS 2008 to create a DLL which is then called by a VFP Executable.
When I compile the DLL on the Development Machine (Windows 7 64 bit) it automatically registers the dll and everything runs exactly as expected.

When I copy the DLL to the Windows Server machine, I assume I need to register it.  I follow this procedure:
Open Powershell (run as administrator)
cd \windows\syswow64
regsvr32 "path to dll here\mydll.dll"
I get the following error:
The Module "path to dll here\mydll.dll" was loaded but the entry-point DLLRegisterServer was not found.
Make sure that "path to dll here\mydll.dll" is a valid DLL or OCX file and then try again.

On the Dev machine - the dll is actually in the bin\release folder where it is put during the compile.  On the WS 2012 machine, I dropped it in the same folder with the installed VFP EXE.

So - what is VS 2008 doing to correctly load this dll on my Development machine that I am not doing manually on the WS 2012 machine.
It is built with Register for Com Interop checked.  I have built it with Target CPU is x86  and dot net framework 2.0 is targeted (advanced compile options).  I have also tried with Any CPU - they both work on the dev machine, but nothing will register on the WS 2012 machine.  I have checked the registry on the WS machine and there are no references to the DLL.  
I have run Process Monitor and find the following:
regsvr32.exe      4176      CreateFileMapping      C:\Program Files (x86)\Software Plus\PMImport.dll      FILE LOCKED WITH ONLY READERS      SyncType: SyncTypeCreateSection, PageProtection:

I am lost as to why this won't register.  This is a dll I created and it doesn't have the DLLRegisterServer in it, but it is not required on the dev machine which is W7.

Thanks
0
Comment
Question by:DonnaOsburn
  • 4
  • 4
  • 2
10 Comments
 
LVL 33

Expert Comment

by:it_saige
ID: 40575792
The simplistic explanation.  Registration is needed for COM.  COM objects (DLL's and EXE's primarily, and are normally comprised of unmanaged code) that are registered have entries created in the registry.  These entries are used by calling assemblies in order to locate and use the COM objects.

In .NET you do not normally need to register your assemblies because .NET uses a different mechanism (probing) to locate dependencies.

https://msdn.microsoft.com/en-us/library/yx7xezcf.aspx

-saige-
0
 

Author Comment

by:DonnaOsburn
ID: 40575815
Okay, but there is nothing in your answer that has anything to do with my question.

It IS compiled as COM object so i need to register it. If I my EXE were created in .NET I would not need to register it, however, I explained my EXE was created with VFP.
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40575905
In order to register your Managed COM object, you need to use REGASM.EXE.
The Assembly Registration tool reads the metadata within an assembly and adds the necessary entries to the registry, which allows COM clients to create .NET Framework classes transparently. Once a class is registered, any COM client can use it as though the class were a COM class. The class is registered only once, when the assembly is installed. Instances of classes within the assembly cannot be created from COM until they are actually registered.
Source

https://msdn.microsoft.com/en-us/library/aa645736(v=vs.71).aspx
http://www.codeproject.com/Articles/12673/Calling-Managed-NET-C-COM-Objects-from-Unmanaged-C
http://www.codeproject.com/Articles/990/Understanding-Classic-COM-Interoperability-With-NE

-saige-
0
 
LVL 40

Assisted Solution

by:Vadim Rapp
Vadim Rapp earned 250 total points
ID: 40575972
Either you need to run regasm with parameter /codebase on the target workstation, or build the setup and deployment project, which will extract all registry information and will have it registered by Installer.

> So - what is VS 2008 doing to correctly load this dll on my Development machine that I am not doing manually on the WS 2012 machine.

It's running the same regasm, which you request by checking the checkbox "Register for COM interop" in project properties/Compile. You can unregister it using action "Clean" on the project.
0
 

Author Comment

by:DonnaOsburn
ID: 40576028
I found 12 copies of RegAsm.exe on the WS 2012 Box. These were the ones I felt were most likely.
c:\Windows\Microsoft.Net\Framework\v2.0.50727
c:\Windows\Microsoft.Net\Framework64\v2.0.50727
c:\Windows\Microsoft.Net\Framework\v4.0.30319
c:\Windows\Microsoft.Net\Framework64\v4.0.30319
I figured it would be the first one since the dll is compiled for Framework 2.0.
I ran it and it gave me no error, no feedback, nothing. It changes the prompt from PS to >> and i can type in whatever i want and nothing happens.  like stop, exit, go away... and it just goes to the next line.  So apparently, i am not doing something correctly.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 40576048
run

regasm <path>\mydll.dll /codebase
0
 
LVL 33

Accepted Solution

by:
it_saige earned 250 total points
ID: 40576055
Sounds like you are in a PowerShell console and not a Command Prompt console.Running regasm with no parameters produces a help list.
To run a command prompt (you will most likely need to be in an Administrative Command prompt to make changes to the registry):

1. Go to the Start Menu and type in cmd.

Capture.JPG[step="2" title="Right-click on 'Command Prompt' and choose 'Run as administrator']Capture.JPG[/step]
[step="3" title="Once open use the cd command to change to the 'C:\Windows\Micorosoft.Net\Framework\v2.0.50727' directory]Tip: As you are typing in the command, if you hit tab, the command processor will attempt to automatically resolve a portion of the path.Capture.JPG[/step]
-saige-
0
 

Author Comment

by:DonnaOsburn
ID: 40576088
Success!
saige - you were correct, I was in PowerShell not Command prompt.  I truly dislike the whole Windows 8/WS2012 visual experience.
Vadim Rapp - the /codebase did not work. I had to use the /tlb option and it registered and ran.

Interestingly enough, where it ran flawlessly on the Win 7 machine, the code had errors that were caught by the WS 2012 box (I had set a date to DBNull instead of Nothing and it barfed.  

thank you both for the quick response and getting me going.  Now I need to figure out how to get inno install to do regasm.
0
 

Author Comment

by:DonnaOsburn
ID: 40576097
I've requested that this question be closed as follows:

Accepted answer: 0 points for DonnaOsburn's comment #a40576088
Assisted answer: 250 points for Vadim Rapp's comment #a40575972
Assisted answer: 250 points for it_saige's comment #a40576055

for the following reason:

I did not accept my own solution however there is some bug forcing me to put a comment in explaining it. So here is my comment!
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40576112
Glad you got it sorted out Donna.

-saige-
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now