Archive for November, 2011
How to fire events from c# activeX COM dll
I want to fire an event to VB6 from an ActiveX COM dll.
I find:
http://stackoverflow.com/questions/1455577/how-can-i-make-an-activex-control-written-with-c-sharp-raise-events-in-javascrip
http://www.freelists.org/post/programmingblind/C-and-COM-creating-COM-events,9
so I start to write the code:
IVideocapEE.cs (interface to export COM method/property)
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface IVideocapEE
{
void StartCapture(string filename);
…
}
IVideocapEE.cs (interface to export COM events)
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface IVideocapEEevents
{
void NotifyVideoInfo(int numDroppedFrame, int numEncodedFrame);
}
VideocapEE.cs (code)
public delegate void NotifyVideoInfoDelegate(int numDroppedFrame, int numEncodedFrame);
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IVideocapEEevents))]
public class VideocapEE : IVideocapEE
{
public event NotifyVideoInfoDelegate NotifyVideoInfo;
…
public void StartCapture(string filename)
{
…
this.NotifyVideoInfo(numDropped,numEncoded);
}
…
}
compile it.
Use in VB6:
Dim WithEvents videocapEE As videocapEE.videocapEE
Private Sub videocapEE_NotifyVideoInfo(ByVal numDroppedFrame As Long, ByVal numEncodedFrame As Long)
MsgBox numDroppedFrame & “-” & numEncodedFrame
End Sub
It works.
Use in C#:
videocapEE = new VideocapEE();
videocapEE.NotifyVideoInfo += new NotifyVideoInfoDelegate(videocapEE_NotifyVideoInfo);
void videocapEE_NotifyVideoInfo(int numDroppedFrame, int numEncodedFrame)
{
MessageBox.Show(numDroppedFrame + “-” + numEncodedFrame);
}
It works
Spegnere un computer da remoto
utilizzando il comando shutdown (http://www.wintricks.it/windxp/xptricks30.html) non sono riuscito a spegnerlo.
ho usato psshutdown http://technet.microsoft.com/en-us/sysinternals/bb897541.aspx e tutto funziona
pshutdown \\nomecomputer -u utente -p password
sql backup & restore database to a different db
to backup “testdb1″ db:
backup database testdb1 to disk='c:\bck1'
go
to restore filelist from backup file:
restore filelistonly from disk='c:\bck1''
go
the operation returns the filelist:
testdb1
testdb1_log
to restore db to testdb2
restore database prova3 from disk='c:\bck1'
with recovery,
move 'testdb1' to 'c:\destination\testdb2dat.mdf',
move 'testdb1_log' to 'c:\destionation\testdb2log.ldf'
go
Come leggere i nomi dei campi di una tabella senza conoscerli! VB6
Ho una tabella, ma non so il nome dei suoi campi. Come fare?
Vado su google
Digito
adodb.recordset vb6 select get field names
spulcio i risultati
mi imbatto in
http://visualbasic.ittoolbox.com/groups/technical-functional/visualbasic-l/how-to-get-recordset-field-name-877933
tra i commenti trovo il codice
Sub ShowFieldsInfo()
Dim rs As New ADODB.Recordset
Dim i As Integer
‘Error handler
On Error GoTo ShowFields_Error
rs.Open “Select * from Routines;”, CurrentProject.Connection
‘get Field Info
For i = 0 To rs.Fields.Count – 1
‘Add textboxes and labels and position and unhide them here
‘lblLabel.Caption= rs.Fields(i).Name
‘Just for example
Debug.Print “Field ” & i & ” = ” & rs.Fields(i).Name & _
” Type = ” & FieldTypes(rs.Fields(i).Type) & _
” Defined Size =” & rs.Fields(i).DefinedSize
Next
‘Get Field data. Silly as you would only collect these one at a time for
display
Do While Not rs.BOF And Not rs.EOF
For i = 0 To rs.Fields.Count – 1
‘txtBox(i)= rs.Fields(i).Value
Debug.Print rs.Fields(i).Name & ” = ” & rs.Fields(i).Value
Next
rs.MoveNext
Loop
ShowFields_Exit:
‘All final code here
On Error Resume Next
rs.Close
Set rs = Nothing
On Error GoTo 0
Exit Sub
ShowFields_Error:
‘Report error and continue with cleanup for block
MsgBox “Error ” & Err.Number & _
” (” & Err.Description & “) in procedure ShowFields of Module
Module1″
Resume ShowFields_Exit
End Sub
Function FieldTypes(FieldType As Integer) As String
Select Case FieldType
Case AdArray: FieldTypes = “AdArray” ’0×2000
Case adBigInt: FieldTypes = “adBigInt” ’20
Case adBinary: FieldTypes = “adBinary” ’128
Case adBoolean: FieldTypes = “adBoolean” ’11
Case adBSTR: FieldTypes = “adBSTR” ’8
Case adChapter: FieldTypes = “adChapter” ’136
Case adChar: FieldTypes = “adChar” ’129
Case adCurrency: FieldTypes = “adCurrency” ’6
Case adDate: FieldTypes = “adDate” ’7
Case adDBDate: FieldTypes = “adDBDate” ’133
Case adDBTime: FieldTypes = “adDBTime” ’134
Case adDBTimeStamp: FieldTypes = “adDBTimeStamp” ’135
Case adDecimal: FieldTypes = “adDecimal” ’14
Case adDouble: FieldTypes = “adDouble” ’5
Case adEmpty: FieldTypes = “adEmpty” ’0
Case adError: FieldTypes = “adError” ’10
Case adFileTime: FieldTypes = “adFileTime” ’64
Case adGUID: FieldTypes = “adGUID” ’72
Case adIDispatch: FieldTypes = “adIDispatch” ’9
Case adInteger: FieldTypes = “adInteger” ’3
Case adIUnknown: FieldTypes = “adIUnknown” ’13
Case adLongVarBinary: FieldTypes = “adLongVarBinary” ’205
Case adLongVarChar: FieldTypes = “adLongVarChar” ’201
Case adLongVarWChar: FieldTypes = “adLongVarWChar” ’203
Case adNumeric: FieldTypes = “adNumeric” ’131
Case adPropVariant: FieldTypes = “adPropVariant” ’138
Case adSingle: FieldTypes = “adSingle” ’4
Case adSmallInt: FieldTypes = “adSmallInt” ’2
Case adTinyInt: FieldTypes = “adTinyInt” ’16
Case adUnsignedBigInt: FieldTypes = “adUnsignedBigInt” ’21
Case adUnsignedInt: FieldTypes = “adUnsignedInt” ’19
Case adUnsignedSmallInt: FieldTypes = “adUnsignedSmallInt” ’18
Case adUnsignedTinyInt: FieldTypes = “adUnsignedTinyInt” ’17
Case adUserDefined: FieldTypes = “adUserDefined” ’132
Case adVarBinary: FieldTypes = “adVarBinary” ’204
Case adVarChar: FieldTypes = “adVarChar” ’200
Case adVariant: FieldTypes = “adVariant” ’12
Case adVarNumeric: FieldTypes = “adVarNumeric” ’139
Case adVarWChar: FieldTypes = “adVarWChar” ’202
Case adWChar: FieldTypes = “adWChar” ’130
Case Else: FieldTypes = “Undefined”
End Select
End Function
Modifico la query, e funziona tutto!
Bene