Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / May 2005



Tip: Looking for answers? Try searching our database.

Returning object pointers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith Sheppard - 24 May 2005 18:04 GMT
I have an ActiveX dll which exposes a public class - let's call it MyClass.

Is it permissible to pass back to a client application an object pointer
created with set xxx = new Myclass within the DLL?

For example, can I give MyClass a method like this:

Public Function Clone() as MyClass
   dim Answer as MyClass
   set Answer = new MyClass

   ' Set various attributes
   set Clone = Answer
End Function

Then in a calling application to say:

   set oNewThing = OldThing.Clone

The above seems to work but I am getting all sorts of unexplained failures
in my application (or even in the IDE when I try to run it in debug mode).
Typical symptoms are trying to access bad memory pointers so I was wondering
if the above could be the source of problems.

Keith
Douglas Marquardt - 24 May 2005 18:30 GMT
Hi Keith:

I do the same thing all the time with no problems.
In fact, I bet the if you created new projects and did the
same thing (simply pass a created instance/clone) between
the projects it will work fine.

That being the case, I would suspect the issue is with what
the code inside the projects are doing.

hth,

Doug.

> I have an ActiveX dll which exposes a public class - let's call it MyClass.
>
[quoted text clipped - 21 lines]
>
> Keith
Karl E. Peterson - 24 May 2005 20:30 GMT
Hi Keith --

Yeah, "what Doug said."  I use this routine, without issue, in a library of mine:

  Public Function Clone() As Matrix
     Dim mRet As Matrix
     ' Create new matrix object, copy this object's
     ' data into it, and return.
     Set mRet = New Matrix
     mRet.Copy Me
     Set Clone = mRet
  End Function

It's that nefarious "something else", I'm afraid.

Sorry...   Karl
Signature

Working Without a .NET?
http://classicvb.org/petition

> I have an ActiveX dll which exposes a public class - let's call it
> MyClass.
[quoted text clipped - 23 lines]
>
> Keith
Keith Sheppard - 25 May 2005 10:15 GMT
>>It's that nefarious "something else", I'm afraid.
Darn it!  I just don't know what I've done to this application apart from
make it just a little bit more complicated.  At first I suspected ListViews
but I've taken out most of those.  What can earth can I do in code to blow
the IDE out of the water?

Keith
Karl E. Peterson - 25 May 2005 18:13 GMT
>>> It's that nefarious "something else", I'm afraid.
> Darn it!  I just don't know what I've done to this application apart
> from make it just a little bit more complicated.  At first I
> suspected ListViews but I've taken out most of those.  What can earth
> can I do in code to blow the IDE out of the water?

You're familiar with the F8 key?  At times like this, I'm not sure there's anything
you can do but track down the exact location of failure.  Usually that will lend
*some* hint.
Signature

Working Without a .NET?
http://classicvb.org/petition

Keith Sheppard - 26 May 2005 09:45 GMT
>>You're familiar with the F8 key?  At times like this, I'm not sure there's anything
>>you can do but track down the exact location of failure.  Usually that will lend
>>*some* hint.
The problem is that it seems to be a moving target.  The act of stepping
through code seems to move the point of failure.

I have actually gone back to the much older technique of putting in trace
points and tracing to file.  It seems to break at bizarre times.  For
example, it can go through the trace point at the end of the subroutine but
fail to get back to the calling code.

Sometimes it doesn't break in the application at all.  It's the IDE which
breaks - usually just after terminating a debug session.

I have finally given up.  I have reverted to the last working version (thank
heavens for Visual Source Safe!) which does not exhibit the problem.  I
shall now add my new feature piece by piece, watching for any signs of it
playing up.  Fortunately, the delays have enabled me to think of a way to
achieve what I was trying to do in a slightly simpler way.

Keith
alpine - 26 May 2005 15:05 GMT
This sounds like a memory cleanup error.  Usually, it has something to
do with string pointers and API calls and is a manifestation of
releasing memory allocated to a string that has already been released.
Were you making any API calls that involved string variables in the
code for your feature?  If not, it could be a problem in one of the
components you are using.

HTH,
Bryan
____________________________________________________________
New Vision Software                   "When the going gets weird,"
Bryan Stafford                     "the weird turn pro."
alpine_don'tsendspam@mvps.org     Hunter S. Thompson -  
Microsoft MVP-Visual Basic     Fear and Loathing in LasVegas

>>>You're familiar with the F8 key?  At times like this, I'm not sure there's
>anything
[quoted text clipped - 19 lines]
>
>Keith
Keith Sheppard - 27 May 2005 09:13 GMT
>>Were you making any API calls that involved string variables in the
>>code for your feature?

It is entirely possible.  Current status is I have scrapped the enhancements
and am re-adding them a bit at a time using a slightly different design
philosophy.  I shall look out for this as an area to be wary of.

Something good came out of the first attempt in that I can avoid a few blind
alleys second time around.

Keith
Keith Sheppard - 27 May 2005 09:15 GMT
>>This sounds like a memory cleanup error.
Another possibility which occurred to me is that I had a number of instances
where a variable of type Object could have contained a pointer to a number
of different object types depending upon context.  I did wonder whether VB
could have got confused and called the destructor for the wrong object type
when it finally did its cleanup.

Keith
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.