Accessing a Form inside a DLL in VB6 - vb6

I am new to Vb6 and working on an application.I have created a standard exe project containing just one form(say Form1) and an ActiveX DLL, both separate projects. I just want to know is it possible to access Form1 and its controls from the DLL? If yes, how can I achieve this?

Yes. It is totally possible. We have code that does this all the time.
In your ActiveX DLL you just need a method that the application can call to show the form.
public sub showTheForm()
MyForm.Show vbModal
end sub
That will work perfectly well. The problem is when you want your form to be a child of an MDI form the main application is running. For this we use a components called MDIExtender from DevComponents.

Related

Accessing Properties within the same project

I'm creating a ActiveX control. I've created a bunch of properties in a User Control and now I want to access those properties in the other modules, classes, forms, etc in the same project but I can't seem to find the correct syntax to do so?
Syntaxt I've tried:
connectString = user_control_name.DBConnectionString
connectString = Property("DBConnectionString")
connectString = Property(DBConnectionString)
connectString = Property Get ("DBConnectionString")
If you want to access a property on an instance of a UserControl on a specific form, you can do:
my_form_reference.my_usercontrol_name.my_property = <whatever>
If you want to access the instance of a UserControl that is in a UserControl, you will have to pass the reference to the UserControl via a property on the containing UserControl.
I generally recommend you don't pass UserControl references around. It is generally better to wrap up these controls, and not break abstraction.
If you want to access a property on an instance of a UserControl from inside the ActiveX Control project, I would recommend against it. The only way you can do this is by using module-level variables in a BAS module. This variable would potentially be accessible from every module in the project. You would have to set the variable in the UserControl_Initialize event of the control. However, I would strongly recommend you not doing this, because this creates an extra reference to your UserControl, which should really only have a reference from the containing Form or UserControl. This extra reference would mean that if the containing Form or UserControl was unloaded, the control would stick around in memory for the lifetime of your application, causing a memory leak. There are ways around this issue by using "weak references". But this is not supported in VB6, requires API hacks, and is prone to causing crashes.
I seriously would suggest you find some other way to do what you want. Perhaps you could explain exactly why you have this requirement.

Design forms in VC++

Till current moment I knew only one recipy to create form VC++ designer:
1. Add dialog resource and design what you want in designer.
2. Create MFC form by using designed dialog resources
But now I got project sample that has form and has no *.rs files with form information. Instead of that it has header file that has form icon. Header file contains many code that creates controls and sets style. It is also possible select from menu "View Designer". That makes me think that there is another way of creating form. Besides that looks that codes does't uses MFC.
How to create simple form application with designer that would generate header file (not resource) and not use MFC?
Unfortunately I can't "View Designer" because during this procedure error is generated:
C++ CodeDOM parser error: Line: 1520, Column: 42 --- Unknown type 'AxKgLib.AxKg'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.
Correct me if I'm wrong. Looks like I need registered ActiveX for this project. I have registered ocx that was included in source, but this didn't helped.
How to solve this problem? How to get list of all ocx that system has to make sure there is no required AxKgLib.AxKg? How to make designer to show me form without required control?

Disabling visual styles in manifest while retaining Common Controls functionality

I'm using pure WINAPI, and need to send the TB_GETMETRICS message. However, that message only works if you add a manifest file to your application with a reference to Common Controls version 6.0. I added it, the message is working, but now my application is using Vista/Windows 7 visual styles, which I do not want.
Is there any way to keep the Common Controls 6.0 reference while using Classic theme, either by modifying the manifest file or by calling some API function?
Note: I tried SetWindowTheme but the result was a mix of Classic and Aero.
EDIT: I hadn't read the SetWindowTheme function correctly, so I was thinking calling it for the parent hWnd would automatically call it for all its child. It turns out I need to call it for each control I want to use Windows Classic. It's working as it should now.
To disable visual styles for all controls, call SetThemeAppProperties(STAP_ALLOW_NONCLIENT) or SetThemeAppProperties(0) before you create your main window.
To disable visual styles per HWND you can call SetWindowTheme(hwndControl,L"",L"")
If you need to support systems without v6 common controls you can probably figure out which system metrics (or hardcoded values) are used in the toolbar control by playing with the system metric values and system DPI.
Solved by using SetWindowTheme (with L"" as parameters) properly: all I had to do was call it for each and every control my application creates. It feels hackish but gets the job done.

Deploying CRM solution

Using the crm 2011 sdk samples I've written a C# routine in Visual Studio to deactivate all active records in a custom entity. Now I'd like to wire this routine to a custom button on ribbon (figured that one out using RibbonDiffXml) However I'm unsure how to go about deploying. Am I creating a dll to register with the plugin registration tool? Any guidance would be appreciated!
As I see it, you have two options:
Rewrite your code to use the Organization Service from JavaScript. You can put the code completely inside the button this way. However, this requires manually constructing the SOAP calls to the API. The SDK has a walkthrough for this.
Include your code in a plugin, create a custom entity that you can register this plugin against, and create an instance of that entity from the JavaScript that will fire when clicking your ribbon button. This is detailed in an answer to a similar question.
Here are even more alternative solutions:
Create a workflow plugin and trigger that workflow (that runs async in the background). Triggered manually, on an event or from a javascript.
Create a javascript but use the REST API or even better, use the CrmRestKit to deal with the REST-part and keep your scripts clean and easy to read and maintain.
Create an ASP.NET page (or silverlight control) that displays a dialog that shows a progress bar while the process is running.

Loading VB forms/UserControls into ActiveX control

I have developed an ActiveX control in VB 6.0. I have a placeholder in my ActiveX control, where I need to load a user control developed in VB 6.0 at runtime. The user control has to be part of another DLL/OCX file.
How do I load the user control in VB dynamically?
All the user controls have some common functionalities. Can I implement the common functionalities in the base class and write only specific code in user control?
You can load the control like any other control, using CreateObject. Then you have to assign the control as a child control to your container. (In a standard VB6 form you can do this with Controls.Add. (See this))
This is possible only to a certain degree. COM/ActiveX is all about composition, there's no inheritance. You could create a helper class which provides the common functionality and is instanciated and used by the user controls.

Resources