-
Hello!
I'm currently developing class for loading resources from resource-only DLL. And I've encounterd one quite strange error. My function looks like this:
Code:
Public Function LoadPicResource(pic as PictureBox, id as long, resType as String) as Boolean
''
'' here is some other code
''
Set pic.Picture = LoadPicture(sFile)
End Function
When I try to compile it, I get compile error: Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as field of public user defined types.
I presume that error occured because of "pic as PictureBox", but I don't know how to repair that. I tried also like this:
Code:
Public Function LoadPicResource(id as long, resType as String) as StdPicure
''
'' here is some other code
''
Set LoadPicResource = LoadPicture(sFile)
End Function
But that also didn't work. When when I tried to run it and it came to line "Set LoadPicResource = LoadPicture(sFile)" it generated an error and VB then crashed. The error was "50002 - Unexpected error". I also tried to define my function as IPictureDisp but VB also crashed. I just don't get it why this happens, because LoadPicture() function is also declared as IPictureDisp.
Is there any way that I can create picture directly to PictureBox through hWnd property or something like that?
Zvonko
-
<?>
It's occuring because it is declared public..
set it in a module or declare it private whichever
is needed for the procedure..
Public Function LoadPicResource(pic as PictureBox, id as long, resType as String) as Boolean
Private Function....or .bas module
[Edited by HeSaidJoe on 07-12-2000 at 07:42 AM]
-
I could do that, but I need it in Class Module.
Any solutions?
-
Something else must be going on because when I create a class that contains your posted code and then do this
Code:
Option Explicit
Public C As Class1
Private Sub Form_Load()
Set C = New Class1
C.LoadPicResource Picture1, 123, "xxx"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set C = Nothing
End Sub
it runs and compiles OK.
-
Let me explain what my procedure really does.
It uses three parameters, picturebox, resource ID and resource type. First it extracts JPEG picture data from resource-only dll and saves it to disk file. Then I set myFunction=loadPicture(file). Maybe there's a problem because of that, but I don't know why. It stops where I set loadpicture(file) to my function and crashes VB.
-
This could be it.
Something is crashing: Either loading the picture, or setting it to the function.
Here's how you check. Change this line:
Code:
Set MyFunction = LoadPicture(File)
To this:
Code:
Dim oTest As Object
Set oTest = LoadPicture(File)
Set MyFunction = oTest
The 1st line isn't crashing. (Unless you have 8 KB of total RAM or something)
Either the 2nd or 3rd lines are crashing. Step through the code and check.
If it's the 2nd file, then maybe there's a problem with extracting the file, or maybe you didn't close it properly after extracting, or maybe the file isn't saved to the DLL correctly. Anything's possible.
If it's the 3rd line, then maybe you should do a manual Set instead. You do this using CopyMemory and the object's pointer. It's probably the 2nd line crashing, though.
Try!
-
Thanks.
I'll try this tomorrow, because here in Slovenia is late, 1 am. Can you post me an example with copymemory if that doesn't work?
-
hokay,
this is a rather common n VERY irritating VB error :) Question, where is the "pic" for the first version of your function Dim'd?? is it in that class module itself?? If it is then in ALL probability its Private n theres your error... make it public n check again.
If not n u're passing it over.. try specifically saying "ByRef Pic as PictureBox", even though the default is ByRef in VB this does do the trick sometimes...
if not.. well then we'll just have to see the rest of the code making up your class..
cheers
Gaurav