NO

Author Topic: MS Type library TLB in Pelles-C project  (Read 6899 times)

sergey

  • Guest
MS Type library TLB in Pelles-C project
« on: April 24, 2016, 01:25:55 PM »
Connect to the Pelles-C project file MS * .TLB (eg c:\Windows\Program Files\Common Files\...)
Is that possible?

What is the difference from the use of MS OCX
If you have experience in the use of TLB in Pelles-C projects we would like to see an example.
I still have Windows-XP.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

sergey

  • Guest
Re: MS Type library TLB in Pelles-C project
« Reply #2 on: April 24, 2016, 03:39:14 PM »
Thank you for your prompt and informative response, frankie.

A series of articles 'COM in plain C' by Jeff Glatt I read.
But I do not understand from them: it is possible-whether in the same way to get access to the objects of the TLB.
Three Your articles will be read and try examples cited therein.

That's right, I realized that 'FTypeLib' allows you to use it MS TLB?
I quite successfully connected the TLB-library from MS VisualBasic-6 environment and work with AutoCAD objects.
But in the environment of VisualBasic all this gets almost automatically, and many of the important things are not even visible to the programmer.

Now I realized that it is necessary to leave the MS-VB and do the same thing from the Pelles-C environment.
« Last Edit: April 24, 2016, 03:41:07 PM by sergey »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: MS Type library TLB in Pelles-C project
« Reply #3 on: April 24, 2016, 04:05:24 PM »
Unfortunately to use automation from plain C there is no 'easy' way. You have to understand, or you can't use them.
My utility FTypeLib scans a TLB, from a .tlb or .dll or .exe file, and build an header file (.h) to be used to link with the OLE/COM code. The articles from Jeff Glatt are the most clear and simple that have ever been wrote on the topic. I suggest you to read them again following the samples.  :P
There is really no other way...
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

sergey

  • Guest
Re: MS Type library TLB in Pelles-C project
« Reply #4 on: April 24, 2016, 04:27:32 PM »
Quote
My utility FTypeLib scans a TLB, from a .tlb or .dll or .exe file, and build an header file (.h) to be used to link with the OLE/COM code.
This is exactly what I need, how to work with objects of TLB I know.
I get the h-file and will read it.
Of course after that there will be other more meaningful questions, but I hope for your help.

I was just confused by the number 64 in all the files in this archive.
If it says about the 64-bit version of Pelles-C, it will be a problem for me - I have all 32-bit.

Thanks again.
« Last Edit: April 24, 2016, 04:37:50 PM by sergey »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: MS Type library TLB in Pelles-C project
« Reply #5 on: April 24, 2016, 06:18:23 PM »
This ICad / progeCAD example is a bit similar as with ACAD
May the source be with you

sergey

  • Guest
Re: MS Type library TLB in Pelles-C project
« Reply #6 on: April 24, 2016, 11:09:45 PM »
Hi TimoVJL !

You helped me very hard (several times) when I learned project LiteCAD.
I remember it well, and thank you for a great and invaluable assistance.
Many thanks.

Several times I tried to understand the code on the page:
http://forum.pellesc.de/index.php?topic=3436.msg13008#msg13008
 and could not do it.
I do not have IntelliCAD and ProgeCAD.
But they are not the problem.

I do not know how to get:
#include "ICADAuto.h" // from ICadAuto.dll
in my case it has to be:
#include "acdb(NN).h" // from acdb(NN).dll or from axdb.dll
It is not clear where there are:
CLSID const IID_IcadApplication = {... ... ... };
CLSID clsid;
pICad
pICadDocs
CLSCTX_ALL

There IcadApplication can be replaced by AcadApplication, but nothing will change until it is written to the equivalent of the MS-VB code:

Code: [Select]
Public Sub ConnectToAcad()

        ' AutoCAD Object
        Dim acadApp As AcadApplication
        Dim acadDoc As AcadDocument
On Error Resume Next
        Set acadApp = GetObject(, "AutoCAD.Application")
        If Err Then
                Err.Clear
                Set acadApp = CreateObject("AutoCAD.Application")
                If Err Then
                        MsgBox Err.Description
                        Exit Sub
                End If
        End If
        ' Connect to the AutoCAD drawing
        Set acadDoc = acadApp.Application.ActiveDocument
        If Err Then
                MsgBox Err.Description
                Exit Sub
        End If
        ' get name of the opened in AutoCAD and active drawing
        Dim DWGname As String
        DWGname = acadDoc.Name
        acadApp.Visible = True
        MsgBox "Now running " & acadApp.Name & " version " & acadApp.Version & "  File: " & DWGname

' ... and so on ...
End Sub ' ConnectToAcad

After that, access to objects such as Point, Line, and all the rest will not be a problem (I'm sure it).
That's why I asked to see an example of working code with access from Pelles-C to MS * .TLB

Yes, I do not quite understand what's inside OCX and do not know how it differs from the TLB
But I am able to apply (to adapt) a real working example.
And the result will be quite interesting and even useful tool.

sergey

  • Guest
Re: MS Type library TLB in Pelles-C project
« Reply #7 on: April 24, 2016, 11:22:18 PM »
Hi frankie !

Example 'scripthost2' placed into a new project Pelles-C (I only have version 5 and 6, but then the example was written in 2013).
As a result, we obtained obj-files, but the exe-file is NOT created.
Here are the compilation log:
Code: [Select]
Building main.obj.
Building TraceWin.obj.
Building ChooseEngine.obj.
Building IActiveScriptSite.obj.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(36): warning #2168: Operands of '=' have incompatible types 'long int __stdcall function(IActiveScriptSite *, LPCGUID const , void * *)' and 'long int __stdcall function(MyRealIActiveScriptSite *, LPCGUID const , void * *)'.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(37): warning #2168: Operands of '=' have incompatible types 'unsigned long int __stdcall function(IActiveScriptSite *)' and 'unsigned long int __stdcall function(MyRealIActiveScriptSite *)'.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(38): warning #2168: Operands of '=' have incompatible types 'unsigned long int __stdcall function(IActiveScriptSite *)' and 'unsigned long int __stdcall function(MyRealIActiveScriptSite *)'.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(39): warning #2168: Operands of '=' have incompatible types 'long int __stdcall function(IActiveScriptSite *, unsigned long int *)' and 'long int __stdcall function(MyRealIActiveScriptSite *, unsigned long int *)'.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(40): warning #2168: Operands of '=' have incompatible types 'long int __stdcall function(IActiveScriptSite *, const wchar_t *, unsigned long int, LPUNKNOWN *, LPTYPEINFO *)' and 'long int __stdcall function(MyRealIActiveScriptSite *, const wchar_t *, unsigned long int, LPUNKNOWN *, LPTYPEINFO *)'.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(41): warning #2168: Operands of '=' have incompatible types 'long int __stdcall function(IActiveScriptSite *, wchar_t * *)' and 'long int __stdcall function(MyRealIActiveScriptSite *, wchar_t * *)'.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(42): warning #2168: Operands of '=' have incompatible types 'long int __stdcall function(IActiveScriptSite *, const VARIANTARG *, const EXCEPINFO *)' and 'long int __stdcall function(MyRealIActiveScriptSite *, const VARIANTARG *, const EXCEPINFO *)'.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(43): warning #2168: Operands of '=' have incompatible types 'long int __stdcall function(IActiveScriptSite *, SCRIPTSTATE)' and 'long int __stdcall function(MyRealIActiveScriptSite *, SCRIPTSTATE)'.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(44): warning #2168: Operands of '=' have incompatible types 'long int __stdcall function(IActiveScriptSite *, IActiveScriptError *)' and 'long int __stdcall function(MyRealIActiveScriptSite *, IActiveScriptError *)'.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(45): warning #2168: Operands of '=' have incompatible types 'long int __stdcall function(IActiveScriptSite *)' and 'long int __stdcall function(MyRealIActiveScriptSite *)'.
C:\Program Files\PellesC\PROJECTS\scripthost2\IActiveScriptSite.c(46): warning #2168: Operands of '=' have incompatible types 'long int __stdcall function(IActiveScriptSite *)' and 'long int __stdcall function(MyRealIActiveScriptSite *)'.

Building scripthost2.exe.
POLINK: error: Unresolved external symbol '__imp__CoCreateInstance@20'.
POLINK: error: Unresolved external symbol '__imp__CLSIDFromString@8'.
POLINK: error: Unresolved external symbol '__imp__CoInitialize@4'.
POLINK: error: Unresolved external symbol '__imp__CoUninitialize@0'.
POLINK: error: Unresolved external symbol '__imp__VariantInit@4'.
POLINK: error: Unresolved external symbol '__imp__VariantChangeType@16'.
POLINK: error: Unresolved external symbol '__imp__VariantClear@4'.
POLINK: error: Unresolved external symbol '_CATID_ActiveScriptParse'.
POLINK: error: Unresolved external symbol '__imp__ProgIDFromCLSID@8'.
POLINK: error: Unresolved external symbol '__imp__CoTaskMemFree@4'.
POLINK: error: Unresolved external symbol '__imp__SysFreeString@4'.
POLINK: fatal error: 11 unresolved external(s).
*** Error code: 1 ***
Done.
« Last Edit: April 24, 2016, 11:35:00 PM by sergey »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: MS Type library TLB in Pelles-C project
« Reply #8 on: April 25, 2016, 09:39:13 AM »
Example 'scripthost2'.
Add libraries ole32.lib and oleaut32.lib to project or to source
Code: [Select]
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "oleaut32.lib")

Example with header generated by frankie's tool.
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define INITGUID
#include <ole2.h>

#define COBJMACROS
#define __AutoCAD_INCLUDEALIAS
typedef DWORD OLE_COLOR;
//line 3197: //typedef INT64 LONG_PTR ; /// allready in basetsd.h
#include "acax18enu.h" // from C:\Program Files\Common Files\Autodesk Shared\acax18enu.tlb

#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "oleaut32.lib")

char *szAppName = "AutoCadTest";

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
HRESULT hr;
CLSID clsid;
IAcadApplication *pACad = NULL;
IAcadDocument *pACadDoc = NULL;

CoInitialize(NULL);
hr = CLSIDFromProgID(L"AutoCAD.Application", &clsid);
hr = CoCreateInstance(&clsid, NULL, CLSCTX_ALL, &IID_IAcadApplication, (void **)&pACad);

if (pACad)
{
IAcadApplication_put_Visible(pACad, -1);
IAcadApplication_get_ActiveDocument(pACad, &pACadDoc);
IAcadApplication_Release(pACad);
}
else
{
MessageBox(0, "No AutoCAD.Application ?", szAppName, MB_OK);
}
CoUninitialize();
return 0;
}
« Last Edit: May 30, 2016, 02:34:21 PM by TimoVJL »
May the source be with you

sergey

  • Guest
Re: MS Type library TLB in Pelles-C project
« Reply #9 on: April 25, 2016, 04:04:18 PM »
It's better, but (AutoCAd-2007):
Code: [Select]
/*!
1. make acax17enu.tlb --> acax17enu.h (4 707 282 bytes)
-------------------------------------------------------
 * Header file generated by FTypeLib - OLE/COM C header generator for PellesC
 * - Ver 00.08.00.00 - Build 0102 ("Mar 13 2015","16:17:33") -
 * Copyright Frankie 2012-2015. License LGPL3 (Free Software Foundation)
 * FTypelib is available on PellesC forum (http://forum.pellesc.de)
 *
 * typelib filename: C:\Program Files\Common Files\Autodesk Shared\acax17enu.tlb
 * uuid(851A4561-F4EC-4631-9B0C-E7DC407512C9)
 * version(1.0)
 * "AutoCAD 2007 Type Library"
 * library AutoCAD
 */

2. compile project
------------------
Building ACADtestTLB.obj.
Building ACADtestTLB.exe.
POLINK: error: Unresolved external symbol '_IID_IAcadApplication'.
POLINK: fatal error: 1 unresolved external(s).
*** Error code: 1 ***
Done.
« Last Edit: April 25, 2016, 04:06:09 PM by sergey »

sergey

  • Guest
Re: MS Type library TLB in Pelles-C project
« Reply #10 on: June 14, 2016, 11:16:05 PM »