.NET King Logo Comments on: .NET DLLs and Unmanaged clients
Skip Navigation Links
Home
Weblog
How to... (video)
Articles
About us
Contact us
0 Items in Video cart!

.NET DLLs and Unmanaged clients (10/2/2006)

This is the e-mail that was forwarded to me containing two questions.
I'm Omar Adel from Gamalearn company. We met the last seminar in Crown Plaza-AbuDhabi, and i took your email to contact you if anything comes up.
As i was working on a new topic, which is creating a Dll using c# in visual studio 2005.
I completely made the dll and then made another program in Vb which calls it and the return values where successfully retrieved.
But, when i tried implementing this 'DLL' in another software that i'am working with, it gave me the following error
"Couldn't find an entry point to the "function name", it has to be exported".
I tried searching for some code samples and solutions for this "entry point" problem but i only found some minor details which doesnt fullfill the purpose.
And so, what i need to ask you is the following:
1- How to create a successful " Dll " with the 'Pinvoke' or the ' Entry point ' so that i can call it from anywhere ?
2- In visual studio 2005, i can create a dll using only c#, or i have to use it along with c++ ??
Thanks for your time, and i will be waiting for your answer
Best,
Omar Adel.. Developer


Dear Omar
 The answer is very simple. When you create a .NET dll, you can call it from any .NET application that has reference to it. But you actually do NOT register .NET assemblies, so each and every single application which calls the should have the full path to the dll, or the dll should be located in the same client application path. The problem happens when you want to deploy the application with the dll to another server or computer. In this case you need to make the dll a shared assembly.
It is also simple. Here are some straight forward references to learn how to do it.
 OK, but as I can see your problem is something else. Most probably you are trying to call the .NET DLL from an unmanaged code (from an application which is not developed with .NET like C++, VB 6.0 or ...). This is impossible without registering the DLL and creating the registry tlb reference. If you want to call a .NET dll from a non-.NET client you need to follow these steps:

  1. inside your DLL create an interface that contains your desired functions and have your class implement the interface (.NET classes are not exposed to unmanaged code and only interfaces are used to create the type library)
     
  2. In visual studio .NET go to your DLL project properties and under the Build tab check the Register for COM interop
  3. Step 2 will creates the required type library for your dll and registers it on the development machine, but to run it on another machine you need to go to Visual Studio .NET command line and use regasm.exe command line tool to register it before calling by an unmanaged code. Remember that it is a .NET dll, so you cannot register it with regsvr32.
  4. When you want to call it in your VB 6.0 application create the object variable of type interface that you created and then assign the class instance to the variable of type interface.
  5. Call any function like the normal com functions.

Important note: Not all your .NET functions will work in unmanaged code. Remember that the .NET specific parameters and return values are not supported in unmanaged code and functions with these return values or parameters will not work in unmanaged client.

Morale: Who cares about unmanaged code, in the near future everything will be .NET and I personally believe most of this hassle does not worth it.
If you need any help or additional explanation, just put a comment for this note.

By the way, a dll is nothing special. In any language that you can make a class and then compile it so that another application can call it, you have made a dll. So you can simply make DLLs out of anything (remember cupcakes in cat in the hat movies - lol).
Cheers
Alireza  


By: alla  
thanks
URL: http://www.google.com  
By: Omar  10/17/2006
Dear Mr ali How is my code going? Iam waiting for your answer on fire. I hope to hear from your sicerely soon enough... Omar
URL:  
By: Omar  10/10/2006
Dear Mr. Ali I hope that you can check the code for me and guide me to the safe shore.. so that i can contiue with the other jobs i have depending on this one .. ill be around.. omar
URL:  
By: Omar  10/7/2006
Dear Mr. Ali This is the code and the comments are available. I have followed all the procedures as you have said. Thank you and ill be following your answers inshalla. //***************************** using System; using System.Collections.Generic; using System.Text; namespace Test { public class Class1 // The class name used.. { public int ValidateName(String arg1) // Taking a string argument { if (arg1 != "Prod1") // condition for stating whether the name desired is right or wrong return 0; /*The '0' and '1' out return values are to state whether the software should continue After getting this value. 0 to stop and 1 to contiue*/ else return 1; } } } // I have registered it and build the dll with the name class1. What to do next ??
URL:  
By: Alireza  10/7/2006
Dear Omar Please send me the dll source code. Let me see what is the problem. Regards
URL:  
By: Omar  10/5/2006
hello again,.. After i have registered the dll in the com interop, it generated a .tlb file. But still, the software that calls the dll function gives me the same message of the entry point. What to do now, what is the net step after the .tlb file ?? Omar
URL:  
By: Omar  10/5/2006
I have solved the problem of the register Com Interop, only remains the Project Dll sample you will send to guide me correctly.
URL:  
By: Omar  10/5/2006
and yeah, one more thing... i tried to use the method you gave me (Register Com Interop). But when i tried to build the dll, it gave me the following warning "Couldn't Find any types to register in the Com Interop" So, if you are kind, could you mention a solution to this point as well as the previous sample.. Thank you soo much Omar
URL:  
By: Omar  10/5/2006
Any Further Luck with my sample ..?? I know am a lil annoying.. but am really persistent to learn and achieve success :) Hope to read from u soon... cheers omar
URL:  
By: Alireza  10/2/2006
Dear Omar I will clarify this in a day or two. Frankly speaking I am too busy these days. But I have a comprehensive answer for you. Take care
URL:  
By: Omar  10/2/2006
first of all, i want to thank you for this vast view you gave me, and i find it very helpfull with my question. But only one thing remains, when i use the dllimport in the c# dll, can i include the same dll that am making? and if i can, how can i define the function prototypes that i have. This is making me so confused, if you can help me with a sample code that demonstrates my question, i would be greatful. Thanks soo much
URL:  
Your name:
Email:
URL:
Comments:
 

 -