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
Accendere computer da remoto in c#
basta copiare il codice c# in un progetto console:
http://community.bartdesmet.net/blogs/bart/archive/2006/04/02/3858.aspx
dove al posto di
byte[] mac = new byte[] {0×00, 0x0F, 0x1F, 0×20, 0x2D, 0×35};
mettere il MAC address ricavato da ipconfig /all
altre info utili:
http://blog.memos.cz/index.php/team/2008/06/12/wake-on-lan-in-csharp
Create a DB via SQL server
CREATE DATABASE dbName
USE dbName
CREATE TABLE (…
ALTER TABLE tableName ALTER COLUMN columnName VARCHAR(12);
very simple!
log tools for programmer
you could use:
log4net: http://logging.apache.org/log4net/index.html
common logging: http://netcommon.sourceforge.net/index.html
System.Diagnostic trace in visual studio
How to do an ActiveX DLL in VB6 Visual Studio 2005
Open visual studio 2005
create a new project ClassLibrary
on Project->Properties->Build
choose “Register for COM interop”
modify assemblyinfo.cs
[assembly: ComVisible(true)]
Add an interface file (IProvaNet.cs):
using System;
using System.Runtime.InteropServices;
namespace provanet
{
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface Iprovanet
{
void provaMetodo(string strValue);
string provaProprieta { get; set; }
}
}
Add a class file (CprovaNet.cs):
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace provanet
{
[ClassInterface(ClassInterfaceType.None)]
public class Cprovanet : Iprovanet
{
private string m_prova = “empty”;
public void provaMetodo(string strValue)
{
m_prova = strValue;
}
public string provaProprieta
{
get { return m_prova; }
set { m_prova = value; }
}
}
}
Test in .NET
Add the class library on reference:
public partial class FormTest : Form
{
private Centera.CCentera m_Centera;
public FormTest()
{
InitializeComponent();
m_Centera = new Centera.CCentera();
}
}
Test in VB6
Add the class library on reference:
Dim m_Centera As centera.CCentera
Private Sub Form_Load()
Set m_Centera = New centera.CCentera
End Sub
Create a “strong name”:
run cmd
cd “C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin”
create a public/private key pair:
sn -k keypair.snk
(If you intend to delay sign an assembly extract the public key:
sn -p keypair.snk public.snk)
on Project->Properties->Signing choose “Sign the assembly” and choose the .snk filename created
Release the Class Library:
compile provanet
set the PATH with the following command:
set PATH=C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin;C:\WINNT\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\bin;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\vcpackages;%PATH%
use regasm to register (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe)
REGASM provanet.dll
To create the tlb use:
REGASM provanet.dll /tlb:provanet.tlb
Use gacutil to add to Global Assembly Cache if you want to use .dll in a different folder of .exe (C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe)
Gacutil /i provanet.dll
Free Technical Online Courses
In the article:
http://www.onlinecourses.org/2009/10/28/100-incredible-open-courses-for-the-ultimate-tech-geek/
you can find 100 free online courses from:
MIT: http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/index.htm
Openlearn: http://openlearn.open.ac.uk/course/category.php?id=7
and some other sites…
Bye
Snippet Compiler & other else
reading an old article from MSDN
“Ten Must-Have Tools Every Developer Should Download Now”
http://msdn.microsoft.com/it-it/magazine/cc300497%28en-us%29.aspx
I found an interesting tool to avoid to use visual studio for few line test code:
Snippet Compiler:
http://www.sliver.com/dotnet/SnippetCompiler.
I repromise also to see:
NUnit for unit testing
http://www.nunit.org/index.php
NDoc: for auto generated project documentation
Nant: for automated building (for example every night)
http://sourceforge.net/projects/nant/
Bye