|
Primary Interop Assemblies would be supplied by the application that you want to interact with, such as Office 2003 or 2007. You can also download the PIA's seperately from Microsoft and run their installer.
|
|
|
|
|
Here is the IDL definition
[
object,
uuid(DAFB7D76-0158-452F-8FD0-FF97A683DEA3),
helpstring("ITest Interface"),
pointer_default(unique)
]
interface ITest : IUnknown
{
[helpstring("method GetString")] HRESULT GetString([out,retval] BSTR* pVal);
};
[
uuid(E768DC15-A19B-407C-ACF9-C420D6FDB1BE),
version(1.0),
helpstring("TestServer 1.0 Type Library")
]
library TESTSERVERLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(788571BD-030B-49CC-8C0A-2DF74E58331A),
helpstring("Test Class")
]
coclass Test
{
[default] interface ITest;
};
};
The ATL COM Library uses APARTMENT threading model.
And the VB.NET windows service code fragment
try
Dim obj As New TESTSERVERLib.Test
Dim s As String
s = obj.GetString()
Catch ex As Exception
WriteToLog(ex.Message)
WriteToLog(ex.InnerException.ToString)
End Try
When the code executes the following error occurs:
Unable to cast COM object of type 'TESTSERVERLib.TestClass' to interface type 'TESTSERVERLib.ITest'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{DAFB7D76-0158-452F-8FD0-FF97A683DEA3}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Object reference not set to an instance of an object.
But the same code works in VB.NET forms application.
Can anyone please explain the reason.
|
|
|
|
|
It appears that the problem comes down to the threading apartment model being used in your service app and your Windows Forms app. They appear to use different models.
You can check this by calling Thread.CurrentThread.AparmentState . It's either going to be STA ot MTA. Your COM component requires one threading model, and gets it under the Windows Forms app, but the service is using the other threading model.
|
|
|
|
|
The Apartment model in the VB.NET windows service is MTA. Whereas in the VB.NET forms application it is STA.
I experimented another method. I wrote a ATL component of type IDispatch interface. It works in both VB.NET forms application as well as VB.NET windows service.
The VB.NET windows service which I am going to write for my customer is a COM library using APARTMENT threading model. QueryInterface fails for all interfaces of type IUnknown. Can you elaborately explain the hidden details of why QueryInterface of type IUnknown fails in a VB .NET windows service and help me to make it work!
Thanks in Advance.
|
|
|
|
|
I have no idea. The internal working of COM are not my strong suit.
|
|
|
|
|
how can i connect crystal report to sql server with vb.net code ? i don know how to make connection for it. can u give me some example of making crystal report connection?
|
|
|
|
|
|
If you just want to update your connection settings (dbname / loginid / loginpass) this code will do:
Private Function reconnectreport(ByVal report As ReportDocument, ByVal servernaam As String, ByVal dbnaam As String, ByVal dbLogin As String, ByVal dbPass As String) As ReportDocument
Try
Dim connection As IConnectionInfo
Dim oldServerName As String = report.DataSourceConnections(0).ServerName
Dim newServerName As String = servernaam
Dim oldDatabaseName As String = report.DataSourceConnections(0).DatabaseName
Dim newDatabaseName As String = dbnaam
Dim userID As String = dbLogin
Dim password As String = dbPass
report = report
' Change the server name and database in main reports
For Each connection In report.DataSourceConnections
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
' SetConnection can also be used to set new logon and new database table
report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
End If
Next
' Change the server name and database in subreports
Dim subreport As ReportDocument
For Each subreport In report.Subreports
For Each connection In subreport.DataSourceConnections
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
' SetConnection can also be used to set new logon and new database table
subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
End If
Next
Next
Return report
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Function
|
|
|
|
|
please help in this regard. give the visual basic code for this as soon possible.
calculate difference between 2 dates and 2 times and display in years, months ,days,hours minutes in vb 6
for eg: if start date is 01/01/2008 and statr time is 10.45 am
end date is 02/02/2009 and end time is 11.45 am
it should display as 1 year 1 month 1 day 1 hour 0 minuts
|
|
|
|
|
Nobody is going to do your homework!
I can tell you that you need to use DateDiff function.
Good luck
Shay Noy
|
|
|
|
|
If your course is in VB6, you should abandon it, it's a fair sign that your teachers are clueless morons.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
It keeps amazing me that there still are schools teaching this.
Couple days ago I answered very similar to you
|
|
|
|
|
Yeah, given that VB6 is obsolete, and VB.NET is free, I can only assume these guys are like the guys who used to teach C++, when they only really knew C.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I got the codes to send sms using VB and i came across these two sample codes.
Sending SMS using .NET[^]
http://www.daniweb.com/forums/post250164-19.html#[^]
I copied and paste the following codes in my Class Library file. i have bold the codes with problems.
Option Explicit On
Imports System
Imports System.Threading
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.IO.Ports
Public Class SMSCOMMS
Private WithEvents SMSPort As SerialPort
Private SMSThread As Thread
Private ReadThread As Thread
Shared _Continue As Boolean = False
Shared _ContSMS As Boolean = False
Private _Wait As Boolean = False
Shared _ReadPort As Boolean = False
Private WithEvents DBServer As Postgres " PROBLEM - type 'Postgres' is not defined "
Public Event Sending(ByVal Done As Boolean)
Public Event DataReceived(ByVal Message As String)
Public Sub New(ByRef COMMPORT As String)
SMSPort = New SerialPort
With SMSPort
.PortName = COMMPORT
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
DBServer = New Postgres() " PROBLEM - type 'Postgres' is not defined "
ReadThread = New Thread(AddressOf ReadPort)
End Sub
Public Function SendSMS(ByVal CellNumber As String, ByVal SMSMessage As String) As Boolean
Dim MyMessage As String = Nothing
'
'Check if Message Length <= 160
If SMSMessage.Length <= 160 Then
MyMessage = SMSMessage
Else
MyMessage = Mid(SMSMessage, 1, 160)
End If
'MsgBox("Sending " & MyMessage & " to " & CellNumber)
If IsOpen = True Then
SMSPort.WriteLine("AT+CMGS=" & CellNumber & vbCr)
_ContSMS = False
While _ContSMS = False
Application.DoEvents()
End While
SMSPort.WriteLine(MyMessage & vbCrLf & Chr(26))
_Continue = False
RaiseEvent Sending(False)
End If
End Function
Private Sub ReadPort()
Dim SerialIn As String = Nothing
Dim RXBuffer(SMSPort.ReadBufferSize) As Byte
Dim SMSMessage As String = Nothing
Dim Strpos As Integer = 0
Dim TmpStr As String = Nothing
While SMSPort.IsOpen = True
If (SMSPort.BytesToRead <> 0) And (SMSPort.IsOpen = True) Then
While SMSPort.BytesToRead <> 0
SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize) 'SMSPort.BytesToRead
SerialIn = SerialIn & System.Text.Encoding.ASCII.GetString(RXBuffer)
' Handle Internal Events
' For Received Characters
If SerialIn.Contains(">") = True Then
_ContSMS = True
End If
If SerialIn.Contains("+CMGS:") = True Then
_Continue = True
RaiseEvent Sending(True)
_Wait = False
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
RaiseEvent DataReceived(SerialIn)
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
End Sub
Public ReadOnly Property IsOpen() As Boolean
Get
If SMSPort.IsOpen = True Then
IsOpen = True
Else
IsOpen = False
End If
End Get
End Property
Public Sub Open()
If IsOpen = False Then
SMSPort.Open()
ReadThread.Start()
End If
End Sub
Public Sub Close()
If IsOpen = True Then
SMSPort.Close()
End If
End Sub
End Class
Next, i have also copied the following codes below into my windows form. I'm not sure if i've pasted the codes in the write place but that is wat i have done.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SMSEngine = New SMSCOMMS("COM1")
SMSEngine.Open()
SMSEngine.SendSMS("919888888888", "SMS Testing")
SMSEngine.Close()
End Sub
The problem i faced is that the SMSEngine was not declared. How do i solve this?
THANKS IN ADVANCE!!
|
|
|
|
|
If you took the time to try and understand the code instead of just Copy'N'Paste what you don't understand and expecting it to work, then you would realize that this code uses a Postgres database for something that probably has nothing to do with sending SMS messages. It looks like you can get rid of those two lines and not worry about them.
|
|
|
|
|
haha. Thanks for your help. I'm new to visual basics and started only a few days ago, so i dun really get what some of the codes are used for. Sorry. haha. I need to use these codes to do a project.
Am i doin things the right way? like where i placed the codes in my program? How do i define or declare the SMSEngine in the codes? thanks
|
|
|
|
|
gjx_junxian1989 wrote: Am i doin things the right way?
Copy'N'Paste coding? Hell No.
gjx_junxian1989 wrote: where i placed the codes in my program?
I have no idea hwere you placed any of this stuff in your app.
gjx_junxian1989 wrote: How do i define or declare the SMSEngine in the codes?
What SMS Engine? Your code snippet doesn't mention anything about an engine. Or are you saying that the code you posted IS the engine? If so, then your problems do not lie in knowing VB.NET, but the basic concepts of object oriented programming. These are design issues that I really can't walk you through in a forum post.
|
|
|
|
|
Hello,
We have a VB.Net program that uses GetObject() method. While executing the program, it gives the following exception.
"Unhandled Exception: System.Exception: Cannot create ActiveX component.
at Microsoft.VisualBasic.Interaction.GetObject(String PathName, String Class)"
The same program is executing successfully in our production environment but not in one of the development environment. We came to know that the program referring to STDOLE.DLL which is not there on the development machine where the program fails. Even if we copy the same dll on that machine, it is not working. How can we install Primary Interop Assemblies seperately? we do not want to install Visual studio.net.
Please let me know what are all the dlls required to use GETOBJECT() method in VB.Net program?
Thank you in advance,
Raheem MA
|
|
|
|
|
Are you sure the ActiveX component is correctly registered? The error you get is not an error of the GetObject function but that your ActiveX component is not registered correctly.
Try to registed the component by executing 'regsvr32 x:\path\myactivex.dll'.
Tosch
|
|
|
|
|
Thank you for quick reply,
We do not have STDOLE.DLL on our machine. So it cannot be registered right? What is required to install on the machine to get this dll? once again reminding you we do not want to install Visual studio.Net.
Thank you,
Raheem MA
|
|
|
|
|
You have to make a setup project from the computer that VS.net is installed on. After that you have to run the setup installation file on the required machine.
Shay Noy
|
|
|
|
|
I think this answer is not related to my question.
I read somewhere that STDOLE.DLL comes with Visual Studio.Net. Are there any alternatives to get this DLL installed without Visual Studio.Net?
Thanks.
|
|
|
|
|
I would like to understand:
Does the program, written on the machine which VS.net is installed on, run succesfully?
If yes, you have to create a new setup project including all the required files (also STDOLE.dll) and then run it in the relevant computer.
Do I understood correctly what you need?
Shay Noy
|
|
|
|
|
yes, our program is a console application which is called from formscape reports. we have copied only exe of the program in the production and running successfully.
On the production system, we have primary Interop Assemblies folder at the following path:
C:\Program Files\Microsoft.NET\Primary Interop Assemblies
Following are the contents of the folder:
1. adodb.dll
2. Microsoft.mshtml.dll
3. Microsoft.stdformat.dll
4. msdatasrc.dll
5. MSDDSLMP.DLL
6. MSDDSP.DLL
7. stdole.dll - This is reffered in our program.
We could not find this folder on development machine. That may be the reason we are getting the exception saying 'Cannot create ActiveX .....".
How can we install these dlls ?
Please shed some light in this scenario.
Thank you in advance
Raheem MA
|
|
|
|
|