-
Sep 24th, 2010, 04:40 AM
#1
Thread Starter
Fanatic Member
Runtime error 398
I've created an OCX which works well when it's placed on a form.
But if somebody tries to use it from a dll using CreateObject() then error 398 occurs. "Client Site not available". (This is the standard error that occurs when a control and its parent lose sight of each other)
The OCX has a tiny form containing just the picture that a developer sees when he drops the ocx on a form but that's not visible at runtime.
Is this error caused by the fact that the ocx has a form - even though it's not visible which causes the error because the parent is a form-less dll or is there some other cause ? Maybe a flag that I need to be setting in the IDE before I compile ?
Other OCXs don't have this problem - is there anything I need to be doing in the ocx to allow it to be used/called/created with CreateObject() from a dll ?
Even if you don't know the 100% answer any thoughts are greatly appreciated.
Thanks
Ian
-
Sep 24th, 2010, 07:21 AM
#2
Re: Runtime error 398
Without knowing what the control does--since it has no GUI, why not just
convert it to AX Dll, which can show a form as well.
-
Sep 24th, 2010, 08:39 AM
#3
Re: Runtime error 398
Is this error caused by the fact that the ocx has a form - even though it's not visible which causes the error because the parent is a form-less dll or is there some other cause ?
No. Most likely you are referencing the UserControl in one of its own initialization events or it has properties that can only exist when sited on a Form.
Post some code.
-
Sep 24th, 2010, 10:04 AM
#4
Thread Starter
Fanatic Member
Re: Runtime error 398
I wrote the ocx - I don't write the application or parent dll where the ocx is used. My task was to create the ocx that it would be dragged/dropped by a developer onto a Form. That works just fine.
But now a developer is trying to use my ocx in a form-less dll. That isn't what the ocx was intended for but I would like to understand the problem and fix it if possible.
Originally Posted by brucevde
Post some code.
I can't post any code from the dll that is calling the ocx - that's not mine - I don't have access to it.
I 'could' post some code from the ocx (that is mine) but which bit. It's a lot of code so which bit do I post ?
Originally Posted by brucevde
No. Most likely you are referencing the UserControl in one of its own initialization events or it has properties that can only exist when sited on a Form.
I don't know what you mean by referencing the UserControl in one of it's own initialization events. - Do you mean that the ocx is referencing itself ?
I do understand that about properties that can only exist when sited on a form. By default a UserControl has properties related to its position (Top/Left/Size etc.) so I'm not sure I can do anything about those (or am I supposed to remove them of they're not needed?) or would the error occur if the ocx was "CHANGING" any of those properties such as changing its position at runtime. I suppose that would be impossible if the ocx wasn't actually on a form.
Last edited by IanS; Sep 24th, 2010 at 10:08 AM.
-
Sep 24th, 2010, 11:13 AM
#5
Re: Runtime error 398
Right so some other guy has written a wrapper dll for your ocx basically ?
Since your OCX needs to be on a form to work, how does this other developer think they will be able to use a formless dll ?
Get him to add a form to his dll and add your ocx to it. Then he will be able to call the form with the ocx on it.
You cant call an ocx which is a control as a form object !!!, it needs to live on a form.
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you
-
Sep 24th, 2010, 01:06 PM
#6
Thread Starter
Fanatic Member
Re: Runtime error 398
The error happens when the ocx does
Code:
If UserControl.Ambient.UserMode then etc etc
It does that so that it can decide if it's running in runtime or in the IDE
Last edited by IanS; Sep 24th, 2010 at 01:14 PM.
-
Sep 24th, 2010, 01:12 PM
#7
Re: Runtime error 398
You cant call an ocx which is a control as a form object !!!, it needs to live on a form.
That is not 100% true. It is possible to instantiate a control without placing it on a Form. It all depends on how the control was written.
I don't know what you mean by referencing the UserControl in one of it's own initialization events. - Do you mean that the ocx is referencing itself ?
Yes. Just like the Me keyword within the Form's code module references a Form instance.
For example, assuming the UserControl contains a Textbox the following will cause an error when instantiating the control using CreateObject.
Code:
Private Sub UserControl_InitProperties()
Text1.Text = UserControl.Ambient.UserMode
End Sub
-
Sep 24th, 2010, 01:28 PM
#8
Thread Starter
Fanatic Member
Re: Runtime error 398
The OCX does not have any UI at all so isn't trying to display anything.
The error happens here:-
Code:
Private Sub UserControl_InitProperties()
If UserControl.Ambient.UserMode then ' error happens on this line
' Do this
else
' Do something else
End If
End Sub
-
Sep 24th, 2010, 01:38 PM
#9
Re: Runtime error 398
All UserControls have a UI - Click, Show, Resize events are part of a UI.
Exactly as it should. The Ambient property is only available after the UserControl is sited on a Form.
What code are you executing within the If Else Block? Maybe there are some alternatives we can suggest.
-
Sep 24th, 2010, 01:50 PM
#10
Thread Starter
Fanatic Member
Re: Runtime error 398
Originally Posted by brucevde
What code are you executing within the If Else Block? Maybe there are some alternatives we can suggest.
If the ocx is being used by a developer in the IDE then it reads some license info from the registry to confirm that the developer has a valid developer license.
If it's runtime then it doesn't do anything, it just runs.
It uses Ambient.UserMode to decide what mode it's in.
-
Sep 24th, 2010, 02:45 PM
#11
Re: Runtime error 398
In standard licensing practices, being able to use CreateObject would require a license key.
Regardless, the only way I know of to get around this would be to capture the error and process accordingly.
-
Sep 24th, 2010, 03:37 PM
#12
Thread Starter
Fanatic Member
Re: Runtime error 398
Originally Posted by brucevde
the only way I know of to get around this would be to capture the error and process accordingly.
That's a fair suggestion.
If an error occurs on that line, especially if err.number is 398, then the ocx can be pretty certain that it's not running in the IDE so no need to do any more checks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|