PDA

Click to See Complete Forum and Search --> : Using Python with Vb6


Vbstr
Dec 16th, 2010, 09:06 AM
well i've searched for two days on how to fix this problem and found nothing. what i'm trying to do is call python functions and stuff from within vb6. Here's the steps I took

1) I have vb6 and sp6 installed
2) I install activepython 2.7 because it includes win COM stuff
3)I create the folder C:\PythonVB
4)I created the python script called 'PythonVB3.py' with the following code


class PythonVB3:
#Public Methods available to VB
_public_methods_ = ['SayHello']
#Class Name Created in VB.
#Example Set objPython = CreateObject("PythonVB3.Demo")
_reg_progid_ = "PythonVB3.Demo"
#Never Copy this GUID! Use pythoncom module to create a new one
#Example: import pythoncom
# print pythoncom.CreateGuid()
_reg_clsid_ = "{EE2946AE-79DD-49D1-992D-F4FF6431A2F0}"

def SayHello(self):
return "Hello from Python!!"

if __name__ =='__main__':
print "Registering COM Server..."
import win32com.server.register
win32com.server.register.UseCommandLine(PythonVB3)


5) I double clicked the script above which registered itself
This tool 'RegDLLView' from nirsoft shows it registered correctly

http://img72.imageshack.us/img72/554/regged.jpg

6)I created a new standard exe project in vb6 with the following code

Private Sub Form_Load()
Dim objPythonVB As Object
Dim retval As Long
Set objPythonVB = CreateObject("PythonVB3.Demo")
retval = objPythonVB.SayHello()
MsgBox retval
End Sub


7)when I compiled and try to execute(in C:\PythonVB) I get error
http://img171.imageshack.us/img171/735/vb6error.jpg

I tried manually adding a reference to pythoncom27.dll too and it wouldn't let me :\ any help or advice would be much appreciated. I also uninstalled/reinstalled everything and only have 1 version of python installed.

Vbstr
Dec 16th, 2010, 04:51 PM
ok I got it to work, i'll leave it unanswered for a day to let people guess if they want. i'll give you a hint though, there's nothing wrong with the code short of retval being declared a long when it should be a string. That's not the main issue though.