registering .net dll in navision

Hey there first post here, I’m stuck here with Navision, I have to create a .dll using Visual C# .NET and then register it in Navision in Custom Controls, so I can use it’s functions. I’ve tried many different ways and settings, but the registering just never works. How must I create my .dll, any special parameters? Thanks in advance.

  1. The DLL cannot be just plain DLL. It has to be an Automation Object or OCX for Navision to be able to use it. 2) Assume that you know how to write the class for the DLL, you need to make it into and COM Object. In VB.Net, I add the following to the beginning of the Class: ---- Begin Code <ComClass(clsWebPull.ClassId, clsWebPull.InterfaceId, clsWebPull.EventsId)> _ ---- End Code And I also Add the GUIDs for these inside the class: ---- Begin Code #Region “COM GUIDs” ’ These GUIDs provide the COM identity for this class ’ and its COM interfaces. If you change them, existing ’ clients will no longer be able to access the class. Public Const ClassId As String = “3F29AC0D-00CD-4832-A764-FF02EE9D59CB” Public Const InterfaceId As String = “001F716F-9EC5-451d-ADF8-2AF6C1439226” Public Const EventsId As String = “E8B1C4B6-E7B2-4eb6-80F2-4069C1DC3891” #End Region ---- End Code 3) With the class in this format, all your public Methods should be exposed, but you may want to force them by Prefacing the method with: ---- Begin Code <ComVisible(True)> _ ---- End Code 4) Finally, you need to turn on the “Register COM Interop” by going: ---- Project/Project Properties/Build/Register COM Interop (it’s a checkbox) Now, in your Navision code, create an globe-variable, of type Automation, and you should see your class in the drop down next to it. Have fun… (I have created a couple Automation Objects for Navision, one for AddressValidation, one for Writing to EventLog. It is extremely easy)

Thanks for your reply, I tried to do as you said but the code has some errors I don’t know how to correct them, here’s what I have: —Begin code---- Public Class Class1 <Class1(clsWebPull.ClassId, clsWebPull.InterfaceId, clsWebPull.EventsId)> _ #Region “COM GUIDs” ’ These GUIDs provide the COM identity for this class ’ and its COM interfaces. If you change them, existing ’ clients will no longer be able to access the class. Public Const ClassId As String = “3F29AC0D-00CD-4832-A764-FF02EE9D59CB” Public Const InterfaceId As String = “001F716F-9EC5-451d-ADF8-2AF6C1439226” Public Const EventsId As String = “E8B1C4B6-E7B2-4eb6-80F2-4069C1DC3891” #End Region <ComVisible(True)> _ Public Function MyFunction(ByVal Param1 As Integer) MsgBox(Param1, MsgBoxStyle.Critical, “Error!”) End Function End Class —End Code---- I changed ComClass to Class1 but I don’t know if that’s correct. Any further input would be extremely appreciated.

I beleive there is an setting in the project to achieve what chubby is describing manually. I havent used it for a while but i think there must be a setting that sais something like “Expose project to COM”. This has to be enabled. But i’m not very sure. Search MSDN, there should be a topic about that.

A couple things caught my eyes… 1) Public Class Class1 <Class1(clsWebPull.ClassId, clsWebPull.InterfaceId, clsWebPull.EventsId)> _ — Should be: <Class1(clsWebPull.ClassId, clsWebPull.InterfaceId, clsWebPull.EventsId)> _ Public Class Class1 2) You cannot use Function with this method if I remember right. You have to use Sub. Also, I didn’t mention the use of Property… I use it to return values… ----------------------------------------------------------------- Anyway, I am attaching a sample class I just started yesterday. ----------------------------------------------------------------- Imports System.Diagnostics Imports System.Runtime.InteropServices Imports System.Data Imports System.Data.SqlClient <ComClass(clsWebPull.ClassId, clsWebPull.InterfaceId, clsWebPull.EventsId)> _ Public Class clsWebPull #Region “COM GUIDs” ’ These GUIDs provide the COM identity for this class ’ and its COM interfaces. If you change them, existing ’ clients will no longer be able to access the class. Public Const ClassId As String = “3F29AC0D-00CD-4832-A764-FF02EE9D59CB” Public Const InterfaceId As String = “001F716F-9EC5-451d-ADF8-2AF6C1439226” Public Const EventsId As String = “E8B1C4B6-E7B2-4eb6-80F2-4069C1DC3891” #End Region Public strWebServer As String Public strWebServerLogin As String Public strWebServerPassword As String Public strWebDBName As String Public strNavServer As String Public strNavDB As String Public Sub InitWebServer() MsgBox(“Yo”) End Sub Public Sub PullNewOrders(ByVal strLastOrderID As String) End Sub Public Sub PushNewOrders() End Sub Public Property WebServerName() As String Get Return strWebServer End Get Set(ByVal Value As String) strWebServer = Value End Set End Property Public Property WebServerLoginName() As String Get Return strWebServerLogin End Get Set(ByVal Value As String) strWebServerLogin = Value End Set End Property Public Property WebServerPassword() As String Get Return strWebServerPassword End Get Set(ByVal Value As String) strWebServerPassword = Value End Set End Property Public Property WebServerDBName() As String Get Return strWebDBName End Get Set(ByVal Value As String) strWebDBName = Value End Set End Property Public Property NavServerName() As String Get Return strNavServer End Get Set(ByVal Value As String) strNavServer = Value End Set End Property Public Property NavDBName() As String Get Return strNavDB End Get Set(ByVal Value As String) strNavDB = Value End Set End Property End Class

You are correct… The setting is described in my previous post. But you still need to set the COM GUIDs, and etc. The only thing I described that was optional was the <ComVisible(True)>. MSDN does contain all these info (spread out over quite a few articles). And there are more ways to get it working. For example, I can just use VB6 or VC6 to get the work done with just a couple checkboxes. MS has put a lot of things backward with Dotnet. A lot of things that used to be extremely difficult are now too easy, and a lot of easy things are very difficult to do. For example, try writing an OCX with VB.net

quote:


Originally posted by janpieter
I beleive there is an setting in the project to achieve what chubby is describing manually. I havent used it for a while but i think there must be a setting that sais something like “Expose project to COM”. This has to be enabled. But i’m not very sure. Search MSDN, there should be a topic about that.


Youre absolutely right. In general i think VB .net is not more easy then VB6 but sure it is more powerfull.

I have tried the same with a good result in prototyping. How will this perform e.g. with multiple users, multiple sessions or on a Citrix Server? Also, I am calling a Non-Automation dll using DECLARE. Will this give me problems? best regards Anders

I have no problem using it under multiple sessions (on the same machine or not) or on Citrix server. I watch for memory leak, and other usual problem. Security might be an issue also. I used this method to call Mappoint Web Service and some WinAPIs. And if I can do that, I see no reason why calling a Non Automation DLL would be a problem.

quote:


Originally posted by Anders
I have tried the same with a good result in prototyping. How will this perform e.g. with multiple users, multiple sessions or on a Citrix Server? Also, I am calling a Non-Automation dll using DECLARE. Will this give me problems? best regards Anders