> When I run the compiled example ("make exe") Project1.exe, I get the
> following error when it tries to invoke the DoWork method/delegate.
> Interestingly, it works fine when I run the same VB6 example from the VB6 IDE
> instead of from the exe.
>
That's because you're debugging in the IDE environment, where memory layouts
are completely different. The application contains a bug, it just isn't
detected when running in the IDE.
> AccessViolationException
>
> Message: "Attempted to read or write protected memory. This is often an
> indication that other memory is corrupt."}
>
Did you get a dialog box with the option to attach a debugger? If so, you
should be able to attach VS and poke around for obviously bad values.
> Source: "NetFX20Wrapper"
>
> StackTrace: " at
> NetFX20Wrapper.BackgroundWorkerWrapper.DoWork.Invoke(Object& argument,
> RunWorkerCompletedEventArgsWrapper& e)
> at NetFX20Wrapper.BackgroundWorkerWrapper.backgroundWorker_DoWork(Object
> sender, DoWorkEventArgs e) in C:\data\ProductionSupport\ETAG\FusionExample\VS
> 2005 NetFX20Wrapper\NetFX20Wrapper\BackgroundWorkerWrapper.vb:line 43
> at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
> at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object
> argument)"
>
> Can anyone provide me hints as to what this might be caused from? I am
> currently researching CAS to see if there are security attributes that might
> resolve this. It appears that .Net is not allowing the VB6 DoWork method to
> be called.
>
No, you're barking up the wrong tree here. CAS causes SecurityExceptions,
not access violations (yes, the terminology can be confusing). The "access"
you're violating is that of an operating system page that you shouldn't be
reading from or writing to, and this is the result of a bad pointer (or
reference, as the case may be here). It has nothing to do with CAS. See the
MSDN on AccessViolationException.
See if objects may be going out of scope and being garbage collected when
you're not expecting them to, or if you've failed to initialize some
critical fields. Alternatively, there may be a mismatch between object
layouts as declared on either side of the fence, or a simple error in
declaring the marshaling interfaces.
--
J.
can you kindly just try the referenced MSDN article example. I have
investigated many avenues and have been unsuccessful.
My bet is that you will run into the same error, running the example. If
you have specific ideas to make this example work, lets talk.
> My bet is that you will run into the same error, running the example.
That's possible and perhaps even likely, but I don't even have the VB
redistributables installed on this machine, let alone a development
environment for VB 6 code! Without that, it's going to be rather hard to
pinpoint the problem.
> If you have specific ideas to make this example work, lets talk.
>
I have no experience with VB6/.NET interop (plenty of experience with
unmanaged interop other than VB, though). Perhaps someone who does can run
the example themselves and tell you specifically what's wrong. All I can
tell you is that the interop is going wrong somehow, but without something
to attach my debugger to I can't be any more specific than that, I'm afraid.
This particular example is marshalling delegates, which is always tricky,
especially when mixing it up with COM and threading.
The author (Scott Swigart) kindly provided his e-mail address with the
sample; if it's still live, he might be willing to take a look.
--
J.
My bad, I misread what you wrote. I did download the sample, but as
mentioned, I can't do anything with it. Well, I can compile the .NET part,
but that's no good.
--
J.
I'm trying the same thing (to get a little more use from some code)
and could not get the exe of the example to work. In my case, it was
'error 91, Object variable or With Block variable not set'. I changed
from compile to native code' to 'compile to P-code' and it ran. I'll
have to see what effect this setting has on my real application.
Good luck.