Walkthrough:Creating an OCX for Navision using C++

I know I’m asking a lot but:- 1. Does any one have an example on how to create an OCX using C++ in Visual Studio.NET 2. Also an example in Navision Attain on how to use this OCX. Don’t laugh but this is my first C++ program apart from “hello World” on a unix machine. I would very greatful for any help or tips. Regards Graham. CBS Sverige AB +46(0)8 764 74 25 graham@cbs.se

There are some examples on how to implement it in Navision in the handbook : Integration. … good luck … you’ll need it I think.

Where can I find this intergration Manual on my Navision attain CD? CBS Sverige AB +46(0)8 764 74 25 graham@cbs.se

Hello Graham. Without knowing the exact nature of your task, I would still advise you to consider the possibility of using ATL, for which the Visual Studio provides a pretty nifty wizard to get the thing going. What you need to do is to create a project, compile it to a dll, and call that interface, therefore accessing your functions. The compiler automatically registers your dll after the compile, which should then appear in navisions automation object’s list. /Tero.

www.partnerguide.com http://www.navision.com/be/view.asp?categoryID=284 Edited by - gco on 2002 Jun 04 16:24:25

Dear Tero Thank you for your good advice about using an ATL, for creating an object that can be used for Navision. Just this tip has helped me on my way. The task is to create a rapper for a dll. I was unable to registers the dll in question. I have created a VB program to solve this problem. But I would like to join the Big Boys and create a C program. Regards Graham CBS Sverige AB +46(0)8 764 74 25 graham@cbs.se

Originally posted by gco: www.partnerguide.com http://www.navision.com/be/view.asp?categoryID=284 Unable to get to this site, Do you have a more General site. Regards Graham CBS Sverige AB +46(0)8 764 74 25 graham@cbs.se Edited by - graham on 2002 Jun 05 11:00:12

Ok this is how fare I’ve got. Thanks to Tero I’ve created a ATL com server using a walkthrough. This is how it goes. (This is from Microsoft MSDN thx Bill). In this walkthrough, you will use the Visual Studio integrated development environment (IDE) and the various wizards to create the same ATL COM server. To create a simple ATL COM server 1. On the File menu, click New, and then click Project. The New Project dialog box appears. 2. Click the Visual C++ Projects node. 3. In the Project Types pane, click Visual C++, and in the Templates pane, click the ATL Project icon. 4. In the Name box, enter MyServer. 5. Click OK. The ATL Project Wizard appears. 6. Click Application Settings. You will see that the Attributed check box is selected by default. 7. Click Finish to close the wizard and generate the project. The result is an inproc ATL COM server without any server objects. 8. On the Build menu, click Build Solution. Building the project successfully registers the server with the operating system. The COM server now needs to implement a simple COM object. To add a server object 1. In Solution Explorer, right-click the MyServer project 2. On the shortcut menu, click Add, and then click Add Class… . 3. In the Templates pane, click the ATL Simple Object item and click Open. The ATL Simple Object Wizard appears. 4. In the Short Name text box, enter Object1. 5. Click Finish to accept the remaining default values. 6. In Class View, right-click the IObject1 node. 7. On the shortcut menu, click Add, and then click Add Property… . 8. For Property type, enter SHORT. 9. For Property name, enter GetANum. 10. Click Finish. 11. In the body of the get_GetANum method of CObject1, replace the comment with the following code: *pVal= 101; 12. On the Build menu, click Build Solution. This rebuilds your solution. Now, you must create a test client application. The problem is…. that the Myserver.dll it is still not appearing in the customer controls in Navision. Using regsvr32 I have unregistered the dll and register it again. This is working ok. Regards Graham CBS Sverige AB +46(0)8 764 74 25 graham@cbs.se

Hello Graham. I have used my ATL component through an automation variable. That is, I’ve created an global variable that has a type Automation, and then selected the ATLs typelibrary as the subtype of this Automation variable. You also may have to change the interface class to the one that doesen’t start with the capital I, because that seems to become as default. The in the code just use CREATE to create an instance of the object, and CLEAR to destroy it when you are done using the object. If you have difficulties getting strings through to Navision, you might find the wrapper class CComBSTR useful to enable conversion to Navision-style BSTR (number of chars in the beginning). Something like this: STDMETHODIMP CMyClass::GetValue(BSTR *lresult) { CComBSTR str1 = “Hello”; *lresult = str1.Copy(); return S_OK; } Hope this helps:) Tero.

Hello Tero. It’s taken me a long time but now I understand what you ment about Automation. In Navision you have 2 ways to communicat to dll’s using OCX or AUTOMATION all depends on how the dll was created. If only I had slow down and read your reply word by word. Thanx. once again.