Creating an application that can be controlled externally via GetObject call - vb.net

I am trying to create a program in VS 2012 (VB) that I can then access via other programs (including Excel's vba) using GetObject or CreateObject. I would like to be able to declare a variable in the client program and assign it a class object from the server program. I have successfully create dlls that I can access (using comClass and registering) but doing this with an exe is eluding me. I have tried creating a comClass and registering it via /REGSERVER but when I try to use GetOBject I get an error saying that it cannot create an ActiveX component. Could anyone enlighten me?
THanks

Kindly follow given Steps
Step 1 : Convert Extension XYS.EXE to XYZ.DLL
Step 2 : Import This DLL to your new Project.
Step 3 : then
Dim Obj As Object = New Test.Form1()
Obj.show()
For an Example :
Create Project Nameed "Test"
Compile Project
Now we get Test.Exe
Change Extension EXE to DLL=> Test.DLL
Now Create Another Project Nameed "Test2"
Import "Test.dll"
Add Button in new project
On Button Click Event put Given Code
Dim Obj As Object = New Test.Form1()
Obj.show()
It Works for Me

Related

VBA CreateObject versus Type Library References

I have build a COM object via ATL, to use compiled C++ in VBA. My type library is (say) "MyObjLib", and the object is "MyObj".
If I use the Object Browser in VBA, all looks good: it shows me the Library as MyObjLib, and within that I see a class MyObj as a member of the library.
If, in VBA, I include this library through the References menu, I can write:
Dim obj as MyObj
Set obj = new MyObj
and it all works fine. However if I try:
Dim obj as Object
Set obj = CreateObject("MyObjLib.MyObj")
it fails with "Runtime Error 429: ActiveX component can't create object."
This is unfortunate as I now want to use the COM object from Python. Any ideas what I am missing?
Thanks for the comments. I spent some time searching my C++ code for the ProgId. Then I stumbled across another SO answer, about someone who had left the ProgId field blank in the ATL Simple COM object Wizard ... which is exactly what I had done! Hence I had never registered the ProgId for the class (and hence no entry in HKCR in the Registy).
I created another project using the Wizard, this time entering a ProgID and copied the syntax from the .rgs file in the new project to my existing one.
Hey presto, CreateObject() works fine now.

Why am i not allowed to create an access object. Is there a special reference that should be referenced? Run-time err: -2146959355 (80080005)

The error comes in this line: Set App...Running Access 2003 and trying to open a form in another database. I've done it before but now it doesn't seem to work. Thanks in advance...
Function OpenDB(DatabasePath As String) As Access.Application
Dim app As Access.Application
Set app = New Access.Application
app.OpenCurrentDatabase DatabasePath
Set OpenDB = app
End Function
After uninstalling Access 2007 Runtime module it seems to work OK. But it opens the whole application and then the form. What I need is open the form in the calling application, and with the tables in the current application ie. reusing the form in another app. Is that possible?

Cannot create VB6 ActiveX dll

I am trying to create a simple VB6 ActiveX exe and call it from Excel.
In VB6 I create an ActiveX DLL project called BigTrev, using all the default settings.
I create a MultiUse class called Trev with a single method containing no code
Public Sub HelloWorld()
End Sub
I make a DLL and register it from the command line (VB6 also registers it for me but I did it using cmd as well anyway).
Then it Excel I create a reference to my DLL in a new workbook. It clearly has been registered because the Intellisense knows about Trev and HelloWorld.
Sub cats()
Dim derek As BigTrev.Trev
Set derek = New BigTrev.Trev
derek.HelloWorld
End Sub
It compiles in Excel, when I step through it it fails in the second line, the Set one. Error message is "ActiveX component can't create object".
Why? I have done this or similar loads of times many years ago when VB6 was used widely, I am using Windows 7 now and I am an admin on my box.
I would suggest registering the DLL (or EXE if that's the direction you've chosen) with the relevant regsvr32.exe. In this case, where you're registering a 32bit DLL for use in 64bit environment, use the one hiding out in c:\windows\syswow64.
Sadly, I don't have Excel (shock, horror) and the spreadsheet I do have (LibreOffice) is 32bit.

stimulsoft report add my function with vb.net

we can add our function with this way
https://www.youtube.com/watch?v=TEYuQmia9IY
but it in c#
i want the way in vb.net
the problem in using namspacing in vb.net
thanks
In the video posted there are some critical steps missing. It seems that they are given for granted but without it you could not achieve a successful reference to your code from the Report Designer.
First: To clarify the problem between VB.NET and C#. If you want to use VB as scripting language for your report you need to set it in the Report Properties. You will find the ScriptLanguage property in the same property grid for the report where they set the reference to your application. Changing this property is not required because this property refers to the code written inside the report not the code in which you have written your app.
Second: In your VB.NET app your code that defines the function should be as this
Namespace MyFunc
Public Class Main
Public Shared Sub ShowMessage(text As String)
MessageBox.Show(text)
End Sub
End Class
End Namespace
Usually in VB.NET you don't define explicitily a namespace (everything is inside the main namespace defined in the project properties) but if you want a separate namespace there is nothing to stop you.
Third: In the Report Code Page you write
Imports WindowsFormApplication2.MyFunc
Fourth: After completing the design of your report remember to save it in the same folder where the application is created. (Usually Project\BIN\DEBUG) Otherwise the reference to your executable will fail.
Fifth: The Stimulsoft assemblies are installed in the GAC, but to be sure that they are found when you run the report don't forget to set their references to Copy Local = True when you run your app inside Visual Studio

A strange behaviour shared variable issue in VB.net

When I was using VB.net , I came across a very strange behaviour, I created a simple test WPF project to reproduce it. here is the details. I have a very simple class, which when an instance is created, the class will create a test.txt file
Public Class Test
Public Sub New()
Using writer As New System.IO.StreamWriter("test.txt")
writer.Write("test")
End Using
End Sub
End Class
Then in the Application.xaml.vb
Class Application
' Application-level events, such as Startup, Exit, and DispatcherUnhandledException
' can be handled in this file.
Shared tt As New Test()
End Class
I simply define a shared variable. my expectation of this are, when I start the application, the variable will be initiated, and a "test.txt" file will be created.
If the Configuration is "Debug" , everything is fine.
If the Configuration is "release", When I start press F5 in Visual Studio 2010, everything is fine as well, it worked as expected, file had been create
But When I start it without debug, press (Ctrl+F5), the variable had not been initiated, file had not been created as I expected.
I am not fully understand why this happen, Can anyone help me out?
Thanks and regards
Is this shared variable accessed somewhere? It could been removed due to compiler optimization. Try to add some code that uses the variable.