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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Get VBAPI to work

ptc-5354572
1-Visitor

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!


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

5 REPLIES 5

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...

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.

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

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

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!

Announcements


Top Tags