Classes

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

Hi,

I'm using an external class (dll) in order to get information out of a
program and when I try to call the functions in the file I can't open it as
it's being used by the other program. How do I get around this? I can't
close the program as it has to run 24/7.

Cheers,

Michael
 
Hi,

I'm using an external class (dll) in order to get information out of a
program and when I try to call the functions in the file I can't open it as
it's being used by the other program. How do I get around this? I can't
close the program as it has to run 24/7.

Cheers,

Michael

If you can't open the file directly - and you can't modify the other
program to open the file in shared mode, then you could always copy
the file to a temp location and then read that file...
 
A dll should not be locked by another program. I have had compile errors if
the dll is in use by another program, but multiple programs should be able to
load and use the dll. Is the dll developed by you, or is it provided as-is
by the other application? You said you get an error when you call the
functions? What error? Creating objects from the dll works ok?
 
Hi,

It's a DLL from a company but they don't provide support or help on how to
access it. I can upload it if you like? It's the SDK for a SatNav program.

Here's the code (stuck in _Load for testing):
Dim odest As DESTSDKLib.Dest

Dim DestGPSDataVar As DESTSDKLib.DestGPSData

odest = New DESTSDKLib.Dest

DestGPSDataVar = New DESTSDKLib.DestGPSData

odest.GetGPSData(DestGPSDataVar)

The error "System.AccessViolationException was unhandled" gets raised on the
last line.

Cheers,

Michael

A dll should not be locked by another program. I have had compile errors
if
the dll is in use by another program, but multiple programs should be able
to
load and use the dll. Is the dll developed by you, or is it provided
as-is
by the other application? You said you get an error when you call the
functions? What error? Creating objects from the dll works ok?
 
Hi,

I'm using an external class (dll) in order to get information out of a
program and when I try to call the functions in the file I can't open it as
it's being used by the other program. How do I get around this? I can't
close the program as it has to run 24/7.

Cheers,

Michael

Sorry, I totally misread your post. Ignore my original replay. It's
the dll that's locked, not a file :)
 
Hi,

It's a DLL from a company but they don't provide support or help on how to
access it. I can upload it if you like? It's the SDK for a SatNav program.

Here's the code (stuck in _Load for testing):
Dim odest As DESTSDKLib.Dest

Dim DestGPSDataVar As DESTSDKLib.DestGPSData

odest = New DESTSDKLib.Dest

DestGPSDataVar = New DESTSDKLib.DestGPSData

odest.GetGPSData(DestGPSDataVar)

The error "System.AccessViolationException was unhandled" gets raised on the
last line.

Cheers,

Michael

Is this a com library? That exception is not because anything is
locked. An AccessViolationException only occurs according to the
documentation:

"when verifiable managed code interacts with unmanaged code or with
unsafe managed code."

So, either you are declaring these functions (using a declare
statement) and your declare is wrong, causing something akin to a null
pointer access, or this is a com component, and there is something
wrong with the automatically generated RCW.
 
Tom Shelton said:
Is this a com library? That exception is not because anything is
locked. An AccessViolationException only occurs according to the
documentation:

"when verifiable managed code interacts with unmanaged code or with
unsafe managed code."

So, either you are declaring these functions (using a declare
statement) and your declare is wrong, causing something akin to a null
pointer access, or this is a com component, and there is something
wrong with the automatically generated RCW.


Can I ask what a COM library is? I've opened it with the object browser and
it just contains Public Enums, Classes, Structures and a few Intefaces (if
that helps).

At the moment all I have is that code that I posted with the DLL referenced
and I'm not aware I'm declared anythng wrong (though admit I don't know what
I should be looking for if I have) - there's certainly no errors at design
time only when I hit F5 then "System.AccessViolationException was unhandled"
error pops up.

Thanks,
 
The DLL in question would not help us without the hardware and other
application, I suspect.

In the debugger, put a break point at the line where you get the error. See
if the values are "Nothing". It could be that creation of the objects is
failing. If you are not familiar with the debugger then I would add this
section of code before the call that fails:

If ((odest is Nothing) or (DestGPSDataVar is Nothing)) then
MsgBox "One or both objects is nothing."
endif
 
Can I ask what a COM library is?

That's a big topic... Basically, it was the technology that VB5 and 6
were based on. It stands fro Component Object Model. It is a binary
standard for sharing objects across multiple languages. .NET while
not based on COM is able to use legacy COM libraries. Can this
library be referenced in a VB5 or 6 project

So, how di you add the reference? Via the com tab or did you browse
to the dll?
I've opened it with the object browser and
it just contains Public Enums, Classes, Structures and a few Intefaces (if
that helps).

Not really :) Since a RCW will be generated automatically, and that
is what you will see in the object browser.
 
Tom Shelton said:
That's a big topic... Basically, it was the technology that VB5 and 6
were based on. It stands fro Component Object Model. It is a binary
standard for sharing objects across multiple languages. .NET while
not based on COM is able to use legacy COM libraries. Can this
library be referenced in a VB5 or 6 project

In VB6 it can be added under Project -> References and viewed in that object
browser without any errors yes.
So, how di you add the reference? Via the com tab or did you browse
to the dll?

I browsed, but I've just checked and it is under the COM tab.

<snip>

Michael
 
In VB6 it can be added under Project -> References and viewed in that object
browser without any errors yes.


I browsed, but I've just checked and it is under the COM tab.

<snip>

Michael- Hide quoted text -

- Show quoted text -

That's what I suspected. This is going to be a COM interop issue. At
this point, can you use it successfully from VB6? Is there any
documentation? Can you give us some clue as to what the method looks
like from VB6? etc.

The problem is most likely that you are not initializing something
properly.
 
lol, I'm Gepard :-)

As you can see, the code works for others just not for me on my computer.
I've tried moving around the files into other directories but no luck yet.

I'm hoping that when I move over to the actual computer I'll be using it'll
resolve. Otherwise I'll just try writing a C# wrapper and use SendMessage to
send the data to my program....

Cheers,
 
lol, I'm Gepard :-)

As you can see, the code works for others just not for me on my computer.
I've tried moving around the files into other directories but no luck yet.

I'm hoping that when I move over to the actual computer I'll be using it'll
resolve. Otherwise I'll just try writing a C# wrapper and use SendMessage to
send the data to my program....


Ok... I've read that link. And many seem to be implying that this
library is free threaded. VB.NET (and C#) are both capable of free
threading, but they turn that off by default (most com components are
not). So, as an experiment, can you create a console application,
reference your component, and put your code in main. Then, make sure
that this attribute is on the Main method:

<MTAThread()> _
Public Shared Sub Main()
' do your code here
End Sub

And see what happens.
 
That's funny! I thought you were Michael!

Michael said:
lol, I'm Gepard :-)

As you can see, the code works for others just not for me on my computer.
I've tried moving around the files into other directories but no luck yet.

I'm hoping that when I move over to the actual computer I'll be using it'll
resolve. Otherwise I'll just try writing a C# wrapper and use SendMessage to
send the data to my program....

Cheers,
 
Tom Shelton said:
Ok... I've read that link. And many seem to be implying that this
library is free threaded. VB.NET (and C#) are both capable of free
threading, but they turn that off by default (most com components are
not). So, as an experiment, can you create a console application,
reference your component, and put your code in main. Then, make sure
that this attribute is on the Main method:

<MTAThread()> _
Public Shared Sub Main()
' do your code here
End Sub

And see what happens.

Thanks for still sticking with this,


I had to delete 'shared' but I still get the same error as before......

Michael
 
<snip>

Just finally got the computer I'll be using up and running tonight,
installed Express and the software and get the same error as before......
 
<snip>

Just finally got the computer I'll be using up and running tonight,
installed Express and the software and get the same error as before......

Well... I'm sorry. You might have to talk to someone with experience
with this component. I don't see anything obviously wrong with your
code, but with out knowing how this is supposed to be used I really
could be missing something. Have Family Tree Mikes suggestion and
debuged to make sure that the values your passing are not nothing?
 
Back
Top