cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Get VBAPI to work

SOLVED
Newbie

Get VBAPI to work

Hello,

 

I've managed to setup the vbapi on my computer, but I still get an error when I want to test my first program. Basically this program just connects to Creo Parametrics 2.0:

 

Imports pfcls

 

Public Class formCreo
Dim asyncConnection As IpfcAsyncConnection = Nothing
Dim cAC As CCpfcAsyncConnection
Dim session As IpfcBaseDimensions

Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
cAC = New CCpfcAsyncConnection()
asyncConnection = cAC.Connect(Nothing, Nothing, Nothing, Nothing)
session = asyncConnection.Session
End Sub


End Class

 

When I click on the button btnConnect I want the program to connect to PTC Creo 2.0 (which is running in the background). Unfortunately an error occurs which says something like (I've got the german version of Visual Studio Express 2013 - so I try to translate the error as correct as possible)

A first chance exception of type "System.InvalidCastException" occured in Creo_VB-Testprojekt.exe.

Additional Information: Unable to cast COM object of type "System.__ComObject" to interface type "pfcls.IpfcBaseDimensions". This operation failed because the QueryInterface call on the COM component for the interface with IID "{FB2B3DD7-6456-39CE-B45C-668B7907BF5D}" failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

 

Since my vb code is nearly an exact copy of the standard code examples, and I don't see any line of code that has to do anything with IpfcBaseDimensions, I suppose that this error occurs in a standard routine, which is started while establishing the connection to Creo. Therefore it would be a problem with the vbapi setup? Unfortunately I'm not able to fix this problem. I tried to google similar problems, but none of the suggested solutions worked for me nor offered me clues for the cause of this problem. So I would be thankful for any suggestions!

 

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Get VBAPI to work

I seem to remember not being able to get the "imports" statement to work. It has been several years and my memory is a bit fuzzy. But otherwise, my code looks fairly similar to yours.

Dim asynconnection As New pfcls.CCpfcAsyncConnectionClass

Dim connection As pfcls.IpfcAsyncConnection

Dim session As pfcls.IpfcBaseSession

connection = asynconnection.Connect("", "", ".", 5)

session = connection.Session

5 REPLIES 5

Re: Get VBAPI to work

Thomas,

Did you reference the Creo library file in your project?

In Visual Basic Express 2010 it is in PROJECT - ADD REFERENCE - COM - CREO VB API TYPE LIBRARY...

Re: Get VBAPI to work

Thanks for your reply!

Yes, I added the Creo reference. I also tried to start the vb_api_unregister.bat, then the vb_api_register.bat again (both as administrator) and add the Creo reference again.

Re: Get VBAPI to work

I seem to remember not being able to get the "imports" statement to work. It has been several years and my memory is a bit fuzzy. But otherwise, my code looks fairly similar to yours.

Dim asynconnection As New pfcls.CCpfcAsyncConnectionClass

Dim connection As pfcls.IpfcAsyncConnection

Dim session As pfcls.IpfcBaseSession

connection = asynconnection.Connect("", "", ".", 5)

session = connection.Session

Re: Get VBAPI to work

Hello Thomas,

You are declaring session variable as of type "IpfcBaseDimensions" and hence you are getting COM exception.

Try it with IPFCBASESSION as mentioned correctly by Mark McDonald.

Regards

Ketan

Re: Get VBAPI to work

Hi, sry that I didn't replied. Unfortunately I had not enough time to get this VBAPI to work and thus had to find another way to solve my task. I will try to find some time to get this working with your tricks as soon as possible Thanks for your help in advance!