Author Topic: DLLC & COM  (Read 2816 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
DLLC & COM
« on: October 09, 2015, 02:02:00 AM »
Hi Charles,

I'm working with QuickBooks to extract the data from their database. It's a rather simple COM request/response based interface and I'm wondering if I can use DLLC for the COM piece?

Here is some info that may help determine if DLLC can be used.

Automate Tedious QuickBooks Tasks with COM-based API

Here is the Intuit API / Developer site resource.

IDN

Here is a VB6 example from the sites samples.

QuickBooks SDK VB6 Example

JRS

  • Guest
Re: DLLC & COM
« Reply #1 on: October 10, 2015, 09:06:46 PM »
I thought I would give Dave's SB COM extension module a try using the QBFC (COM) method of QuickBooks data access. For some reason I'm unable to make this work.  :'(

Quote from: Dave
I also added a new export TypeName(obj) which will return the class name of the COM object.
I am pretty much done with another command which will allow you to list the public methods/properties of a given com object
The SBCallBackEx export, usable by VB5/6 UIs now also allows the VB form to call back into script basic function using arbitrary number
of arguments of string or long type, and can handle string or long return values from script basic back to vb

In the excel example, any of the variables startign with o are COM object pointers, there are a bunch of them.

without the dot notation, you have to handle access one step at a time.

so in vbscript the single line:

Set ExcelWorkbook = ExcelApp.Workbooks.Add

Has to be converted out to:

oWorkBook = CallByName(oExcelApp, "Workbooks", vbGet)
oExcelWorkbook = CallByName(oWorkBook, "Add")


Here is an example of accessing an Excel spreadsheet using Dave's SB COM ext. module.

I attached the IDN SDK Developer Guide if you're interested in this project.

VB6 Example - From Intuit Developer Network SDK
Code: Visual Basic
  1. Dim MySessionManager As QBSessionManager
  2. Set MySessionManager = New QBSessionManager
  3. MySessionManager.OpenConnection2 “ “, “My Sample App”, ctLocalQBD
  4. MySessionManager.BeginSession "", omDontCare
  5. ' "MyMsgRequestSet" here is a fully formed message request set:
  6. ' we left out that part to keep this as simple as possible
  7. Dim MyDataExt_resp As IMsgSetResponse
  8. Set MyDataExt_resp = MySessionManager.DoRequests(MyMsgRequestSet)
  9. MySessionManager.EndSession
  10. MySessionManager.CloseConnection
  11.  

Script BASIC COM My humble attempt.
Code: Script BASIC
  1. import COM.inc
  2.  
  3. oqbXMLRP = CreateObject("QBSessionManager")
  4. oOpenConnection = CallByName(oqbXMLRP, "OpenConnection", vbGet)
  5. oqbFileOpenSingleUser = CallByName(oqbXMLRP, "qbFileOpenSingleUser", vbGet)
  6. ticket = CallByName(oqbXMLRP, "BeginSession", vbGet, "", oqbFileOpenSingleUser)
  7.  
  8. xml_request = """
  9. <?qbxml version="8.0"?>
  10. <QBXML>
  11.   <QBXMLMsgsRq onError="stopOnError">
  12.      <AccountQueryRq requestID="1">
  13.      </AccountQueryRq>
  14.   </QBXMLMsgsRq>
  15. </QBXML>
  16. """
  17.  
  18. post = CallByName(oqbXMLRP, "ProcessRequest", vbMethod, ticket, xml_request)
  19. CallByName(oqbXMLRP, "EndSession", vbMethod, ticket)
  20. PRINT post,"\n"
  21. CallByName(oqbXMLRP, "CloseConnection")
  22.  

I have installed the QBFC13 & 12 IDN supplied installers as well as the IDN SDK itself. I'm wondering if I need to REGSRV the OLE control as well.  :o

Here is an included module used with the VB6 example of accessing QuicksBooks data. (pointing to I may need to register the control first)

Code: Visual Basic
  1. Attribute VB_Name = "CoCreateInstanceExModule"
  2. ' Module: CoCreateInstanceExModule
  3. '
  4. ' Description: Misc. functions and procedures
  5. '
  6. ' Taken from Microsoft Corp. MSDN website (http:\\msdn.microsoft.com)
  7. '
  8. ' Copyright © 2002 Intuit Inc. All rights reserved.
  9. ' Use is subject to the terms specified at:
  10. '      http://developer.intuit.com/legal/devsite_tos.html
  11. '
  12. '--------------------------------------------------------------------
  13.  
  14. Option Explicit
  15.  
  16. Private Type GUID
  17.       Data1 As Long
  18.       Data2 As Integer
  19.       Data3 As Integer
  20.       Data4(7) As Byte
  21. End Type
  22.  
  23. Private Type COSERVERINFO
  24.       dwReserved1 As Long  'DWORD
  25.      pwszName As Long     'LPWSTR
  26.      pAuthInfo As Long    'COAUTHINFO *
  27.      dwReserved2 As Long  'DWORD
  28. End Type
  29.  
  30. Type MULTI_QI
  31.       pIID As Long   'const IID*
  32.      pItf As Object 'Interface *
  33.      hr As Long     'HRESULT
  34. End Type
  35.  
  36. Public Enum BindingType
  37.       EARLY_BINDING = 0
  38.       LATE_BINDING = 1
  39. End Enum
  40.  
  41. Public Enum CLSCTX
  42.       CLSCTX_INPROC_SERVER = 1
  43.       CLSCTX_INPROC_HANDLER = 2
  44.       CLSCTX_LOCAL_SERVER = 4
  45.       CLSCTX_REMOTE_SERVER = 16
  46.       CLSCTX_SERVER = CLSCTX_INPROC_SERVER + CLSCTX_LOCAL_SERVER + CLSCTX_REMOTE_SERVER
  47.       CLSCTX_ALL = CLSCTX_INPROC_SERVER + CLSCTX_INPROC_HANDLER + CLSCTX_LOCAL_SERVER + CLSCTX_REMOTE_SERVER
  48. End Enum
  49.  
  50. Private Const IID_IUnknown As String = "{00000000-0000-0000-C000-000000000046}"
  51. Private Const IID_IDispatch As String = "{00020400-0000-0000-C000-000000000046}"
  52. Private Declare Function CLSIDFromString Lib "OLE32" (ByVal lpszCLSID As Long, pclsid As GUID) As Long
  53. Private Declare Function CLSIDFromProgID Lib "OLE32" (ByVal lpszProgID As Long, pclsid As GUID) As Long
  54. Private Declare Function CoCreateInstanceEx Lib "OLE32" (rclsid As GUID, ByVal pUnkOuter As Long, ByVal dwClsContext As Long, pServerInfo As COSERVERINFO, ByVal cmq As Long, rgmqResults As MULTI_QI) As Long
  55. Private Declare Function api_GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  56. Private Declare Function api_GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  57.  
  58. Public Function GetUser()
  59.  
  60. Dim Buff As String
  61. Dim BuffSize As Long
  62. Dim result As Long
  63. BuffSize = 256
  64. Buff = Space$(BuffSize)
  65.  
  66. result = api_GetUserName(Buff, BuffSize)
  67. GetUser = Trim$(Buff)
  68.  
  69. End Function
  70.  
  71. Public Function GetComputerName()
  72.  
  73. Dim Buff As String
  74. Dim BuffSize As Long
  75. Dim result As Long
  76. BuffSize = 256
  77. Buff = Space$(BuffSize)
  78.  
  79. result = api_GetComputerName(Buff, BuffSize)
  80. GetComputerName = Trim$(Buff)
  81.  
  82. End Function
  83.  
  84. Public Function CreateObjectEx(ByVal Class As String, Optional ByVal Server As String = "", Optional Binding As BindingType = LATE_BINDING) As Object
  85.    
  86.    ' Creates an Instance of an OLE Server on a specified computer.
  87.   '
  88.   ' Arguments:
  89.   '
  90.   ' The Class argument specifies the OLE Server.
  91.   ' There are two formats for the Class argument:
  92.   '   1. PROGID: "Excel.Application"
  93.   '   2. CLSID: "{00000010-0000-0010-8000-00AA006D2EA4}"
  94.   ' If a ProgID is used, the client's registry is used to get the CLSID.
  95.   '
  96.   ' The Server argument specifies the server computer.
  97.   ' There are two formats for the Server argument:
  98.   '   1. UNC ("\\ServerName" or "ServerName")
  99.   '   2. DNS ("server.sub.com" or "135.5.33.19")
  100.   ' The Server argument is optional. If it is not supplied,
  101.   ' the ole server is created on the client computer.
  102.   '
  103.   ' The Binding argument specifies the type of binding used by client.
  104.   ' There are two values: EARLY_BINDING and LATE_BINDING.
  105.   '
  106.   ' If the client uses late binding (e.g. dim obj as Object),
  107.   ' it must use the LATE_BINDING value or omit the Binding argument.
  108.   ' If the client uses early binding (e.g. dim obj as MySvr.MyClass),
  109.   ' it may use either LATE_BINDING or EARLY_BINDING.
  110.   ' Some OLE servers will work only with LATE_BINDING, others
  111.   ' only with EARLY_BINDING, and others with either binding type.
  112.   ' OLE servers written in Visual Basic 5.0 support both binding types.
  113.  
  114.    Dim rclsid As GUID
  115.    Dim riid As GUID
  116.    Dim hr As Long
  117.    Dim ServerInfo As COSERVERINFO
  118.    Dim mqi As MULTI_QI
  119.    Dim Context As Long
  120.  
  121.    ' Convert IID string to binary IID
  122.   If Binding = EARLY_BINDING Then
  123.         hr = CLSIDFromString(StrPtr(IID_IUnknown), riid)
  124.    Else
  125.         hr = CLSIDFromString(StrPtr(IID_IDispatch), riid)
  126.    End If
  127.    If hr <> 0 Then Err.Raise hr
  128.  
  129.    'Setup the MULTI_QI structure.
  130.   mqi.pIID = VarPtr(riid)
  131.  
  132.    'Convert provided CLSID or ProgID string into a binary CLSID
  133.   If ((Left(Class, 1) = "{") And (Right(Class, 1) = "}") _
  134.                     And (Len(Class) = 38)) Then
  135.       hr = CLSIDFromString(StrPtr(Class), rclsid)
  136.    Else
  137.       hr = CLSIDFromProgID(StrPtr(Class), rclsid)
  138.    End If
  139.    If hr <> 0 Then Err.Raise hr
  140.  
  141.    'Decide on the appropriate context value.
  142.   If Server = "" Then
  143.       Context = CLSCTX_SERVER
  144.    Else
  145.       Context = CLSCTX_REMOTE_SERVER
  146.    End If
  147.  
  148.    'Setup the COSERVERINFO structure.
  149.   ServerInfo.pwszName = StrPtr(Server)
  150.  
  151.    ' Create an instance of the object using CoCreateInstanceEx
  152.   hr = CoCreateInstanceEx(rclsid, CLng(0), Context, _
  153.                             ServerInfo, CLng(1), mqi)
  154.    If hr <> 0 Then Err.Raise hr
  155.  
  156.    Set CreateObjectEx = mqi.pItf
  157.  
  158. End Function
  159.  

I used regsrv32 to register QBFC13.dll & QBFC12.dll with no change with my program.

[attachment deleted by admin]
« Last Edit: October 10, 2015, 10:20:10 PM by John »

Charles Pegge

  • Guest
Re: DLLC & COM
« Reply #2 on: October 11, 2015, 11:57:58 PM »
Hi John,

Due to demands of the physical world, my time is so limited, so unfortunately I will have to confine my support to oxygen core language only. COM and the vastness of applications that use it, defeats me.

I now have care responsibilities for my 89 year old mum, who is very good company, but tends to fall over.

JRS

  • Guest
Re: DLLC & COM
« Reply #3 on: October 12, 2015, 12:06:06 AM »
Thanks Charles for the reply!

I fully understand life's demands and commitments. Let me know if there is anything I can do to help OxygenBasic along on its journey.

Allowing the O2 code to mature and settle is allowing Roland and others time to create external frameworks.

Dave has gone MIA with the SB COM project as has Peter so moving Script BASIC along as a project has been slow. I haven't given up on trying to make Dave's COM stuff work with the QuickBooks SDK yet.  >:(

Charles Pegge

  • Guest
Re: DLLC & COM
« Reply #4 on: October 13, 2015, 01:21:33 AM »
Thanks John,

I've noticed activity has been fairly low on several Basic web sites. But I don't know how this compares with other languages. I think most activity has shifted to the top end of the coding pyramid.