tag:blogger.com,1999:blog-48673758816006694612024-03-12T21:17:10.423-04:00VB6 to C#From VB6 to Visual C# 2010 .NET 4.0. Includes code for interfacing Visual Basic 6 to the R project, MT4 to the R project, C# to the R project, and information regarding forex trading.Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-4867375881600669461.post-24894655662140076492014-05-12T01:27:00.002-04:002015-06-08T08:04:20.638-04:00Code to Export C# DLL to Metatrader Build 600+This is a quick followup to the article <a href="http://vb6-to-csharp.blogspot.com/2012/04/code-to-export-c-dll-to-metatrader.html" target="_blank">Code to Export C# DLL to Metatrader</a> to update the code for Metatrader build 600+ due to the many comments I have received.<br />
<br />
The good news: most things stay the same, particularly with regards to the dll call from MQL4. The changes in C# are relatively straightforward.<br />
<br />
With build 600+, strings must now be explicitly specified in C# with the following format:<br />
[return: MarshalAs(UnmanagedType.LPWStr)]<br />
<br />
I added in this update two array examples. The first shows how to pass a double array as a parameter to C# and do something with those values (calculate the mean of 5 sample values) in C#. The second example shows how to pass an array by reference to C#. The MT4 end of things is identical. In C# you simply specify [In, Out...] to allow the array to be bi-directional.<br />
<br />
Here is the C# (updated) code:<br />
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; background-image: none !important; border: 1px inset; height: 498px; overflow: auto; padding: 6px; width: 500px;">using System;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace testUMD600
{
class Test
{
[DllExport("AddInteger", CallingConvention = CallingConvention.StdCall)]
public static int AddInteger(int Value1, int Value2) {
MessageBox.Show("Add Integers: " + Value1.ToString() + " " + Value2.ToString(), "AddInteger");
return (Value1 + Value2);
}
[DllExport("AddDouble", CallingConvention = CallingConvention.StdCall)]
public static double AddDouble(double Value1, double Value2) {
MessageBox.Show("AddDouble: " + Value1.ToString() + " " + Value2.ToString(), "AddDouble");
double Value3 = Value1 + Value2;
return (Value3);
}
[DllExport("AddDoubleString", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPWStr)] // note this change for build 600+
public static string AddDoubleString(double Value1, double Value2) {
MessageBox.Show("AddDoubleString: " + Value1.ToString() + " " + Value2.ToString(), "AddDoubleString");
double Value3 = Value1 + Value2;
return (Value3.ToString() );
}
[DllExport("returnString", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPWStr)] // note this change for build 600+ as well as MarshalAs statement on the next line...
public static string returnString ([MarshalAs(UnmanagedType.LPWStr)] string Input) {
MessageBox.Show("Received: " + Input, "returnString");
return ("SEND to MT4");
}
// many thanks to anonymous for the code sample below!
[DllExport("ReturnDouble2", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static double ReturnDouble2() {
return 4.5;
}
// a double array is passed in as a parameter from MT4, for the purposes of this demo,
// only the first five (or fewer) items in array data are processed.
// An average is created from the first 5 items in data and returned to MT4,
// and those first 5 items items are shown in a message box for validation purposes.
[DllExport("PassDoubleArray", CallingConvention = CallingConvention.StdCall)]
public static double PassDoubleArray ([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] double[] data,
int datasize)
{
string ff = "first five items (or less):";
int end = 5;
if (end > data.Length) end = data.Length;
double ave = 0.0;
for (int i = 0; i < end; i++) {
ff = ff + " " + data[i].ToString();
ave += data[i];
}
if (end == 0) end = 1;
ave /= end;
MessageBox.Show("Received " + ff, "PassDoubleArray");
return (ave);
}
/*
NOTE:
The key with array passing (as a parameter to C#) is the SizeParamIndex field (above).
When SizeParamIndex is equal to 1 (shown above) the size of the array data must be contained
In the parameter in slot 1 (the 2nd parameter).
This is fulfilled by the variable datasize. If datasize were the first parameter, then SizeParamIndex = 0 would
be appropriate.
This is inferred from this page:
www.mql5.com/en/articles/249
(See 4.3 example 3 as well as some others)
Note how both arrays reference SizeParamIndex = 1 which is the "len" parameter in slot 1 (2nd parameter).
Also note the use of [In Out MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] when passing an array by reference in that example,
and below in PassDoubleArrayByref example.
*/
[DllExport("PassDoubleArrayByref", CallingConvention = CallingConvention.StdCall)]
public static double PassDoubleArrayByref ([In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] double[] data,
int datasize) {
string ff = "first five items (or less):";
int end = 5;
if (end > data.Length) end = data.Length;
double mean = 0.0;
for (int i = 0; i < end; i++) {
ff = ff + " " + data[i].ToString();
mean += data[i];
}
if (end == 0) end = 1;
mean /= end;
// subtract the mean from each of the first values in data
ff = ff + "\r\n" + "Data passed back to MT4: " + "\r\n" ;
for (int i = 0; i < end; i++) {
data[i] -= mean; // subtract the mean
ff = ff + " " + data[i].ToString();
}
MessageBox.Show("Received " + ff, "PassDoubleArrayByref");
return (mean);
}
[DllExport("PassStringArrayByref", CallingConvention = CallingConvention.StdCall)]
public static void PassStringArrayByref ([In, Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 1)] IntPtr[] stringPointer, int datasize) {
try {
// I don't know why we need to pass a fake size 3x larger than the array size but this seems to work this way.
// Use at your own risk!!!
// Not every index contains string values so you must go through and select the items with a valid pointer
string[] data = new string[stringPointer.Length/3];
int datacount = -1; // used to properly index the data array
for (int i = 0; i < stringPointer.Length; i++) {
if (stringPointer[i] != IntPtr.Zero) {
datacount++;
data[datacount] = Marshal.PtrToStringAuto(stringPointer[i]);
if (datacount == 0) {
// attempt to alter the incoming string going back to MT4
stringPointer[i] = Marshal.StringToBSTR("String returned byref from C# DLL!!!");
} else {
// show how it is possible to append data to an existing string (symbol names) and send back to MT4
System.Security.SecureString alteredData = new System.Security.SecureString();
foreach (char c in (data[datacount] + "_modified by C#")) {
alteredData.AppendChar(c);
}
stringPointer[i] = Marshal.SecureStringToBSTR(alteredData);
}
MessageBox.Show(data[datacount], "PassStringArrayByref");
} else {
MessageBox.Show("Pointer " + i.ToString() + " is zero!", "PassStringArrayByref");
}
}
} catch (Exception ex) {
MessageBox.Show("Exception at PassStringArrayByref: " + ex.ToString(), "PassStringArrayByref");
}
}
}
}
</pre>
<div>
<br /></div>
<div>
<br /></div>
<div>
Here is the MT4 (updated) code:</div>
<div>
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; background-image: none !important; border: 1px inset; height: 498px; overflow: auto; padding: 6px; width: 500px;">//+------------------------------------------------------------------+
//| testDLL600.mq4 |
//| Copyright © 2014, Patrick M. White |
//| https://sites.google.com/site/marketformula/ |
//| updated 5/12/2014 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, Patrick M. White"
#property link "https://sites.google.com/site/marketformula/"
#property version "1.00"
#property strict
#import "testUMD600.dll"
// nothing changed on the MT4 side. String handling changed in C#
int AddInteger(int Value1, int Value2);
double AddDouble(double Value1, double Value2);
string AddDoubleString(double Value1, double Value2);
string returnString(string Input);
double ReturnDouble2();
// note that the two calls below are identical, the key is in the C# dll adding
// [In, Out... to PassDoubleArrayByref
double PassDoubleArray(double &data[], int datasize);
double PassDoubleArrayByref(double &data[], int datasize);
void PassStringArrayByref(string &data[], int datasize);
#import
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
Print("AddInteger: " + DoubleToStr(AddInteger(250, 750),0));
double a = AddDouble(250,750);
Print("AddDouble: " + DoubleToStr(a,4));
double d = StrToDouble(AddDoubleString(250, 750));
Print("AddDoubleString: " + DoubleToStr(d,4));
string temp = "Send to DLL";
string recv = returnString(temp);
Print(recv);
double dd = ReturnDouble2();
Print("Returning Double from C#: " + DoubleToStr(dd, 4));
double data[];
ArrayResize(data, 5);
string s = "Sending: ";
for (int i = 0; i < ArraySize(data); i++) {
data[i] = i + 1.0;
s = s + " " + DoubleToStr(data[i],1);
}
Print(s);
double ret = PassDoubleArray(data, ArraySize(data));
Print("Mean of 1+2+3+4+5: " + DoubleToStr(ret, 4));
ret = PassDoubleArrayByref(data, ArraySize(data));
s = "Receiving sent values less their mean: ";
for (int i = 0; i < ArraySize(data); i++) {
s = s + " " + DoubleToStr(data[i],2);
}
Print(s);
// string array demo:
string sa[];
ArrayResize(sa, 4);
sa[0] = "Test from MT4 to DLL";
sa[1] = "EURUSD";
sa[2] = "USDJPY";
sa[3] = "AUDUSD";
PassStringArrayByref(sa, ArraySize(sa)*3); // pass fake size 3x larger - why? it works!
for (int i = 0; i < ArraySize(sa); i++) {
Print("PassStringArrayByref index: " + i + " size: " + ArraySize(sa) + " text: " + sa[i]);
}
}
//+------------------------------------------------------------------+
</pre>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
I just tested the above script in MT4 build 646 and it worked correctly.<br />
<br /></div>
<div>
As a reminder, compile the dll in C# with Platform / Platform Target for x86 (Project / Properties / Build ). </div>
<div>
<br /></div>
<div>
The build 600+ project can be downloaded at <a href="https://sites.google.com/site/marketformula/vb6-to-c/vb6-to-c-downloads/code-to-export-c-dll-to-metatrader" target="_blank">Code to Export CSharp DLL to Metatrader 600+</a>.<br />
<br />
Instructions to get the Unmanaged Exports (DllExport for .NET) for C# via nuget can be found <a href="https://www.nuget.org/packages/UnmanagedExports" target="_blank">here</a>.<br />
<br />
Edit and VERY important note: you MUST handle all errors produced by your DLL, inside your DLL or those errors will feed back to the calling application, causing MT4 to shut down. While the code samples above notably don't show this implemented, you should include a default try{} catch (Exception ex) {} block in each of your C# methods to prevent this from happening. There have been MANY comments from those attempting to implement this code that has prompted this edit, so take note!<br />
<br />
6/8/2015 Edit: Added code to allow byref passing of string arrays to/from C# and a demo on how one might use this to pass symbol names to the DLL, modify a string in the DLL and pass back to MT4. Note only the code above in this blog post has been changed. The uploaded code has not been updated, so copy/paste here to get the updated code. Also note that this was done by trial and error and so the 3x array size hack may not work in all cases. So do your own testing and report back what you learn. If you have a better way to define or make the method call for passing a string array from MT4 to C#, please report your findings here so we can all learn.<br />
<br /></div>
<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com27tag:blogger.com,1999:blog-4867375881600669461.post-56285121216192863012013-05-18T04:50:00.000-04:002013-05-18T04:55:09.194-04:00Triangular Arbitrage with Bid Ask PricesIs is possible to identify triangular arbitrage opportunities using bid and ask prices for a theoretical risk free trade? Using simple rules and examples it is possible to determine the proper formula for computing triangular arbitrage relationships. The three examples show how to calculate the triangular arbitrage formula for different currency pairs due to the way pairs are converted to base currency and traded via currency pairs. The results can be intuitively interpreted to determine if a real arbitrage opportunity exists, or if an opportunity exists to improve execution price by using the synthetic pair instead of the underlying pair for trade execution even when no real arbitrage opportunity exists.<br />
<br />
<img alt="Triangular Arbitrage with bid ask prices 1000 bid vs synthetic ask quotes.png (654×446)" height="273" src="https://911dec9a-a-62cb3a1a-s-sites.googlegroups.com/site/marketformula/home/Triangular%20Arbitrage%20with%20bid%20ask%20prices%201000%20bid%20vs%20synthetic%20ask%20quotes.png?attachauth=ANoY7cp8RKDdeR3rrh2BVjqI-TJ_K2SrRodeZJ5SjDf6DEAKyOxe0FaUAoNY-iUGsw9-YcNi9_nZTl2bvMjcv80pTcPZ46D5sZWVRubiL4ihM5pU_JspfcBGMeqhUkfebu1f9IyCH1DSy2HJsj5RlhJaqHDrg_4Of1MCqo7fHp-jNPHKYitknK6r9CtacGfkXlitrsupamVh6QJiHUiMTR1BeXYePnewLH0vxO770TM14h3HSeeeSUNXnrewhlIHV4KFqHlTR4WTLw4bfda14c23ZC6N4qufr5Gd26CSHHmYyRzRzsvupzoIx0gQVkZITas0aDdGuPkp&attredirects=0" width="400" /><br />
<h2>
<a href="https://sites.google.com/site/marketformula/articles/triangular-arbitrage-101/triangular-arbitrage-bid-ask-quotes" style="background-color: white; color: #2970a6; font-family: Verdana, 'BitStream vera Sans', Helvetica, sans-serif; font-size: 12px; line-height: 17px; margin: 0px; padding: 0px; text-decoration: none;" target="_parent">Triangular Arbitrage with Bid Ask Quotes</a></h2>
<br /><div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com2tag:blogger.com,1999:blog-4867375881600669461.post-55032143309478578552013-04-04T04:31:00.000-04:002013-04-04T04:31:42.483-04:00VB6 VBA Read Large Binary Flat Files Past 2GB Limitation Using Windows API ReadFile WriteFileIf you deal with really large flat files in VB6 or VBA, how do you read past the 2 GB limitation? Visual Basic 6 / VBA has a very easy file read/write mechanism for binary files. It works great for user defined types (UDTs) and arrays of UDTs. Unfortunately, this interface was written before terabyte hard drives became standard. The actual limit is the size of a long integer (2,147,483,647). When reading using the binary Get function, I had the unpleasant experience of rolling the record number, which resulted in the value becoming negative, triggering a read error. I was fortunate to find a well-written demo that gives a solution using the Windows API file read / write methods to ReadFile and WriteFile. You can find the demo and more information at the link below:<br />
<br />
<a href="http://www.xtremevbtalk.com/showthread.php?p=1338338" target="_blank">VB6 HugeFixedFile</a><br />
<br />
The code contains a class that encapsulates the basic methods you will need to deal with large files in VBA and VB6. See the code and forum posts for more details. I have since ditched the UDT interface as I found that LSet didn't do a great job converting my byte array to UDT. So I manually convert the byte arrays into the proper types. I had to find / build functions to convert a byte array to an integer and a long. The code is posted below in case some of you might find it useful to convert a byte array to an integer or a byte array to a long in VB6 or VBA:<br />
<span style="background-color: #f4f6f9; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 13.600000381469727px;"><br /></span>
<span style="background-color: #f4f6f9; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 13.600000381469727px;">Code:</span><br />
<pre class="alt2" dir="ltr" style="background-color: #f4f6f9; border: 1px inset; font-family: monospace, serif; font-size: 12px; height: 130px; line-height: 13.600000381469727px; overflow: auto; padding: 6px; white-space: pre-wrap; width: 640px; word-wrap: break-word;">Private Function ConvertByteToInteger(ByVal start As Long, ByVal lend As Long, ByRef byt() As Byte) As Integer
ConvertByteToInteger = byt(start) + CLng(byt(lend)) * 256
End Function
Private Function ConvertByteToLong(ByVal start As Long, ByVal lend As Long, ByRef byt() As Byte) As Long
ConvertByteToLong = byt(start) + CLng(byt(start + 1)) * 256& + CLng(byt(start + 2)) * 2& ^ 16 + CLng(byt(lend)) * 2 ^ 32
End Function</pre>
<br />
I also ditched the UDTs though the code at the link above shows how to convert a byte array to UDT using LSet. I found that by using the HugeFixedFile class and loading a byte array of 1000 records of 16 byte records, my processing time was cut by almost 2/3 when reading a large file. As a result, I edited the Read function (found in the demo) to allow for reading a larger byte array than the record count as follows: (assumes a zero-based byte array)<br />
<br />
<div class="smallfont" style="background-color: #f4f6f9; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 13.600000381469727px; margin-bottom: 2px;">
<div class="smallfont" style="font-size: 12px; line-height: 13.600000381469727px; margin-bottom: 2px;">
Code:</div>
<pre class="alt2" dir="ltr" style="border: 1px inset; font-family: monospace, serif; font-size: 12px; height: 162px; line-height: 13.600000381469727px; overflow: auto; padding: 6px; white-space: pre-wrap; width: 640px; word-wrap: break-word;">Public Function ReadRec(ByRef Record() As Byte) As Long
If ReadFile(hFile, VarPtr(Record(0)), UBound(Record) + 1, ReadRec, 0) Then
If ReadRec = 0 Then
fEOF = True
End If
Else
RaiseError HFF_READ_FAILURE
End If
End Function</pre>
</div>
<div class="smallfont" style="background-color: #f4f6f9; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 13.600000381469727px; margin-bottom: 2px;">
<br /></div>
<div class="smallfont" style="background-color: #f4f6f9; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 13.600000381469727px; margin-bottom: 2px;">
<br /></div>
<div class="smallfont" style="background-color: #f4f6f9; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 13.600000381469727px; margin-bottom: 2px;">
<br /></div>
<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0tag:blogger.com,1999:blog-4867375881600669461.post-72298767729735977532013-01-23T14:27:00.002-05:002013-01-23T22:11:12.855-05:00Calculating Triangular Arbitrage Lot Size<br />
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">
Have you ever wondered how to correctly size positions between the underlying pair and its synthetics to eliminate or hedge directional risk? This article describes how to calculate triangular arbitrage lot size to fully hedge all exposure when initiating a triangular arbitrage trade. The arbitrage trade is at the heart of all good strategies that take advantage of inefficiency. In the forex market this means triangular arbitrage, so understanding how to correctly size positions to eliminate or minimize individual currency risk is very important.</div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">
<br /></div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">
<a data-mce-href="https://sites.google.com/site/marketformula/articles/triangular-arbitrage-101/triangular-arbitrage-lot-size" href="https://sites.google.com/site/marketformula/articles/triangular-arbitrage-101/triangular-arbitrage-lot-size">Triangular Arbitrage Lot Size</a></div>
<div style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">
<br /></div>
<div class="mceTemp" style="color: #333333; font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">
<div class="separator" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;">
<img alt="Triangular Arbitrage Lot Size" class=" " data-mce-src="https://sites.google.com/site/marketformula/articles/triangular-arbitrage-101/triangular-arbitrage-lot-size/Triangular%20Arbitrage%20Lot%20Size%202.png?attredirects=0" height="226" src="https://sites.google.com/site/marketformula/articles/triangular-arbitrage-101/triangular-arbitrage-lot-size/Triangular%20Arbitrage%20Lot%20Size%202.png?attredirects=0" style="-webkit-user-drag: none; border: 0px none; margin-bottom: 0px; margin-top: 0px; padding: 0px;" title="Triangular Arbitrage Lot Size" width="400" /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<br />
<dl class="wp-caption alignleft" data-mce-style="width: 682px;" id="" style="background-color: #f3f3f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); float: left; margin: 10px 0px; padding-top: 4px; text-align: left; width: 682px;"><dd class="wp-caption-dd" style="font-size: 11px; line-height: 17px; margin: 0px; padding: 0px 4px 5px;">What triangular arbitrage lot size should be traded to capture this 6 pip inefficiency?</dd></dl>
</div>
<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0tag:blogger.com,1999:blog-4867375881600669461.post-1122677310466035162013-01-01T16:19:00.001-05:002013-01-01T16:19:49.170-05:00Trading Search EngineGet better search results for your trading search queries by using the:<br />
<br />
<a href="https://sites.google.com/site/tradingsearchengine/">Trading Search Engine</a><br />
<br />
Perfect for stock, forex, bond, foreign exchange, and commodity traders and trading.<br />
<br />
Make sure to bookmark the link for future access!<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0tag:blogger.com,1999:blog-4867375881600669461.post-61681051990230783212012-10-25T18:47:00.000-04:002012-10-25T18:47:54.045-04:00Harness the Power of Machine Learning in MT4 to Create a Metatrader Indicator with EncogThis step by step guide shows how to create and test an <a href="http://www.heatonresearch.com/encog">Encog</a> machine learning method using inputs from MT4 indicators to create an indicator that can be used in Metatrader. By using machine learning methods such as neural networks, genetic algorithms, support vector machines and other <a href="http://www.heatonresearch.com/wiki/Machine_Learning_Method">machine learning methods</a> Encog allows an ensemble approach to design of machine learning indicators that may be used in MT4.<br />
<br />
This looks very interesting!<br />
<br />
<a href="http://www.heatonresearch.com/wiki/Creating_a_MQL4_Indicator_with_Encog">Creating a MQL4 Indicator with Encog</a><div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0tag:blogger.com,1999:blog-4867375881600669461.post-44891931363072667082012-09-17T20:39:00.000-04:002012-09-17T21:04:24.739-04:00C# ZeroMQ Install Step by Step for Visual Studio.<a href="http://www.zeromq.org/"><b>ZeroMQ</b></a> is a socket library that has many uses and claims to be faster than TCP for clustered products and supercomputing. Sounds interesting! In attempting to install ZeroMQ for C# in Visual Studio, I found that the documentation was not very clear, and nowhere could I find a step by step guide for installing C# ZeroMQ.<br />
<br />
This post is made so I can recall the ZeroMQ C# installation steps for future reference, and in hopes that someone else might have an easier path to ZeroMQ installation in Visual Studio.<br />
<br />
The easiest way to get ZeroMQ working for C# is by using a Visual Studio Extension called <a href="http://nuget.org/">NuGet</a>. To <a href="http://nuget.codeplex.com/releases/view/64974">download NuGet from within Visual Studio</a>, use the <b>Tools / Extension Manager</b> menus.<br />
<br />
From within Visual Studio's Extension Manager, click on <b>Updates</b> and wait for the list to populate. Select <b>NuGet Package Manager</b>, and wait for the package to download and install.<br />
<br />
To display the <a href="http://nuget.org/packages?q=distributed">NuGet Package Manager</a> select <b>View / Other Windows / Package Manager Console</b> from the menus. Make sure your Visual Studio project is set to either x64 or x86 from the <b>Project / Properties</b> menu in Visual Studio, then install the appropriate package from the link above<br />
<br />
The installation package for ZeroMQ is clrzmq 2.2.5 or clrzmq-x64 for x86 or x64 projects respectively.<br />
<br />
In Visual Studio's Project Manager Console type one of the following in:<br />
<br />
<span style="background-color: red; color: cyan;">PM></span> <b>Install-Package clrzmq -Version 2.2.5</b><br />
<span style="background-color: red;"><span style="color: cyan;">PM></span></span> <b>Install-Package clrzmq-x64</b><br />
<br />
This command will install the appropriate version in your package. I created an x64 project with the command directly above. This created a new directory under my project.<br />
<br />
Open up <b>Windows Explorer</b> and find your project's folder. You should see a new subfolder called packages\clrzmq-x64.2.2.5\content that contains the <b>libzmq.dll</b> library if you are doing an x64 project.<br />
<br />
Copy libzmq.dll to your \bin\Debug or \bin\Release directory so that your project can find the dll.<br />
<br />
Prepare one of the <a href="https://github.com/imatix/zguide/tree/master/examples/">sample codes that are available on github for C#.</a><br />
<br />
For your next project you will need to once again use the Package Manager Console to build the libzmq.dll and create the clrzmq and clrzmq-ext References in C#, so make a note of the installation command and file copying procedure for future reference:<br />
<br />
<br />
<span style="background-color: red; color: cyan;">PM></span> <b>Install-Package clrzmq -Version 2.2.5</b><br />
<span style="background-color: red;"><span style="color: cyan;">PM></span></span> <b>Install-Package clrzmq-x64</b><br />
<div>
<b><br /></b></div>
<br />
As a post script, the <a href="http://www.zeromq.org/intro:get-the-software">ZeroMQ Windows installation</a> doesn't seem to be necessary for C# users. In fact, I uninstalled it and was still able to run my demo project. The installation contains some executables and dlls, as well as a number of help documents that may be of interest to developers.<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com3tag:blogger.com,1999:blog-4867375881600669461.post-3325629935303642472012-09-11T06:40:00.000-04:002012-09-11T06:40:34.546-04:00Writing A Chunk of Data to File in C# and VB6<span style="font-family: Verdana, sans-serif;">In Visual Basic 6 / VBA it is possible to quickly write a lot a data to file in just a couple of steps. By creating a user defined type that contains the data, and then using an array of user defined types, all that data can be loaded from and saved to disk in a very easy manner. Below is some pseudo code melded from a couple of my VB6 projects to illustrate the point for loading all data in one shot:</span><br />
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13.63636302947998px; margin: 5px 20px 20px;">
<div class="smallfont" style="font-size: 11px; margin-bottom: 2px;">
VB6 Code:</div>
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; border: 1px inset; height: 250px; overflow: auto; padding: 6px; width: 200px;">' declarations
' 16 byte data storage
Private Type TimeSales5
ntSymNum As Byte
ntDay As Byte
ntMonth As Byte
ntYear As Integer
ntHour As Byte
ntMinute As Byte
ntSecond As Byte
ntBid As Long
ntAsk As Long
End Type</pre>
</div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13.63636302947998px; margin: 5px 20px 20px;">
<div class="smallfont" style="font-size: 11px; margin-bottom: 2px;">
VB6 Code:</div>
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; border: 1px inset; height: 330px; overflow: auto; padding: 6px; width: 540px;">' Main Load Routine
Sub LoadFromFile(ByVal sName as string)
dim uTick() as TimeSales5
iFreeTSFile = FreeFile
Open "C:CompleteData2\" & sName & ".ts3" For Binary As #iFreeTSFile
cLen = LOF(iFreeTSFile)
lRecords = cLen / 16 - 1
If lRecords >= 0 Then
' size the uTick type to receive all the file's records
ReDim uTick(lRecords)
<b>Get #iFreeTSFile, , uTick ' load all the data</b>
' code to assign the fields from uTick to native
' types (double, long etc)
End If
End Sub</pre>
</div>
<div style="font-size: 13.63636302947998px;">
<span style="font-family: Verdana, sans-serif;">Simple VB6 code to save all data in a user defined type one line of code based on the snippet above might be:</span><br />
<span style="font-family: Verdana, sans-serif;"><b>Put #iFreeTSFile, , uTick</b></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Is there an equivalent to VB6 binary file writing of user defined types in C#? I searched quite a bit for a simple yet elegant solution to reading and writing custom file formats in C#. The answer, it seems is using C#'s Stream object for file access and BinaryFormatter to serialize a custom data class to and from disk.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Now that the table has been set, it's time for a paradigm shift from the VB6 mentality of writing binary files to the C# way of writing data to file via Serialization. There are other ways to write data to file in C# but using C# Serialization and DeSerialization for file writing and reading seems most similar to writing a VB6 user defined type to file in one shot or reading from file in one shot.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="background-color: #f5f5ff; font-family: Verdana, sans-serif; font-size: 13.63636302947998px;">Code from SaveFormat class</span><br />
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13.63636302947998px; margin: 5px 20px 20px;">
<div class="smallfont" style="font-size: 11px; margin-bottom: 2px;">
C# Code:</div>
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; border: 1px inset; height: 308px; overflow: auto; padding: 6px; width: 640px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyNamespace {
<b>[Serializable()]</b>
class SaveFormat {
private static int MAXROWS = 1000;
private static int MAXTABS = 50;
public DateTime[] dateTime = new DateTime[MAXROWS];
public double[, ,] EquityCurve = new double[4, MAXTABS, MAXROWS];
public int[] EquityCurveIndex = new int[MAXROWS];
}
}</pre>
</div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;">
<span style="background-color: #f5f5ff; font-size: 13.63636302947998px;">Note the [Serializable()] attribute which tells C# that the SaveFormat class may be written to and read from a file. The class can contain any data format you need to store and retrieve, including as in the above example, multidimensional arrays.</span><br />
<span style="background-color: #f5f5ff; font-size: 13.63636302947998px;"><br /></span>
<span style="background-color: #f5f5ff; font-size: 13.63636302947998px;">Code from SaveFile class</span></div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13.63636302947998px; margin: 5px 20px 20px;">
<div class="smallfont" style="font-size: 11px; margin-bottom: 2px;">
C# Code:</div>
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; border: 1px inset; height: 424px; overflow: auto; padding: 6px; width: 640px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
namespace MyNamespace {
class SaveFile {
public static void SaveMultiA(SaveFormat Data, string name) {
try {
using (Stream stream = File.Open (name , FileMode.Create)) {
BinaryFormatter bin = new BinaryFormatter();
<b>bin.Serialize(stream, Data);</b>
}
} catch (IOException ex) {
MessageBox.Show("Error Saving SaveFormat Storage Class : "
+ ex.ToString());
}
}
}
}</pre>
</div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;">
<span style="background-color: #f5f5ff; font-size: 13.63636302947998px;"></span></div>
<div style="font-size: medium;">
<span style="background-color: #f5f5ff; font-family: Verdana, sans-serif; font-size: 13.63636302947998px;">The SaveFile class essentially just creates a new C# Stream object with the specified file name and the FileMode.Create option. This stream object is then plugged into a new BinaryFormatter object using the Serialize method. The entire SaveFormat class (and this could be any format) is then serialized to disk via BinaryFormatter.</span></div>
<div>
<span style="background-color: #f5f5ff; font-size: 13.63636302947998px;"><br /></span></div>
<span style="background-color: #f5f5ff; font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13.63636302947998px;">And finally this is the LoadFile class</span><br />
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13.63636302947998px; margin: 5px 20px 20px;">
<div class="smallfont" style="font-size: 11px; margin-bottom: 2px;">
C# Code:</div>
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; border: 1px inset; height: 456px; overflow: auto; padding: 6px; width: 640px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
namespace MyNamespace {
class LoadFile {
public static void LoadMultiA(ref SaveFormat Data, string name) {
try {
if (!File.Exists(name)) return;
using (Stream stream = File.Open (name , FileMode.Open)) {
BinaryFormatter bin = new BinaryFormatter();
<b>Data = (SaveFormat)bin.Deserialize(stream);</b>
}
} catch (IOException ex) {
MessageBox.Show("Error Loading SaveFormat Storage Class : "
+ ex.ToString());
}
}
}
}</pre>
</div>
<div style="font-size: 13.63636302947998px;">
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;">
<span style="font-family: Verdana, sans-serif; font-size: small;">The LoadFile class just does this in reverse. Again a new Stream object is created with a valid file name, using the FileMode.Open option. The stream object is then plugged in again to the BinaryFormatter object using the Deserialize method. the Data is cast as (SaveFormat) to ensure the proper translation of the bits.</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: 13.63636302947998px;"><b>Allow me to pause for a moment to admire the beauty of the C# code I just posted.</b> While this may seem like a lot of code, sans the using statements, this is just a few lines of actual code in C# and it gives me that good feeling I get from the pithy VB6 code being able to read and write in one swift, decisive operation. Beautiful!</span></div>
</div>
</div>
<br /><div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com2tag:blogger.com,1999:blog-4867375881600669461.post-40675854149752935612012-08-14T15:02:00.000-04:002012-09-04T09:18:40.231-04:00Calling R From C# .NET (CSharp DotNet)<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">As mentioned in a previous post about <a href="http://vb6-to-csharp.blogspot.com/2012/08/Calling-R-From-VB6-VBA.html">Calling R From VB6 VBA</a>, I've been using 7Bit's very useful utility to call R from VB6. It is so useful that I needed to have the same capability in C#. So I took my VB6 interface and translated it to C#.</span><br />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;"><br /></span>
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">Originally the mt4R.dll tool was created to interface to R from Metatrader. Knowing that this is a windows DLL, therefore mt4R can be accessed from a number of languages, including <a href="http://vb6-to-csharp.blogspot.com/2012/08/Calling-R-From-VB6-VBA.html">VB6</a> and now C#, if a suitable interface is used.</span><br />
<br />
A simple class interface was born in C# that allows .NET users to access R via calls to the mt4R dll. I'm about to embark on a project that will use this newly minted interface in C#.<br />
<br />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">I've been using this for some time in VB6 but as I'm moving more of my development to C#, and I've decided it was time to share with everyone else. So I put together a simple demo application that shows how to access mt4R.dll in a simple C# Windows form application.</span><br />
<br style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">You can download </span><a href="https://sites.google.com/site/marketformula/vb6-to-c/vb6-to-c-downloads/calling-r-from-csharp-dotnet">Calling R From CSharp DotNet</a><span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">. (Please follow the instructions on that page) for use in your own projects.</span><br />
<br style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">C# / .NET developers don't need to worry about transposing matrices to get them to work in R. R and C# arrays are set up the same way:</span><br />
<br />
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; border: 1px inset; color: #222222; font-size: 13.63636302947998px; height: 34px; overflow: auto; padding: 6px; width: 640px;">A[row, column]</pre>
<br style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" />
<span style="background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;">Please let me know if you have any comments, questions or problems getting this code to work.</span><div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com5tag:blogger.com,1999:blog-4867375881600669461.post-82793713373906936672012-08-14T14:49:00.000-04:002012-08-14T16:04:14.552-04:00Calling R From VB6 VBAI've been using 7Bit's very useful utility to call R from VB6. Originally the mt4R.dll tool was created to interface to R from Metatrader. Knowing that this is a windows DLL, therefore mt4R can be accessed from a number of languages, including VB6, and <a href="http://vb6-to-csharp.blogspot.com/2012/08/calling-r-from-csharp-dotnet.html">C#</a> if a suitable interface is used.<br />
<br />
To that end I translated the existing Metatrader interface to a simple drop-in VB6 class that may be accessed in Visual Studio, or from VBA from Excel. This handy interface in conjunction with 7Bit's dll allows a VB6 / VBA developer to access the power of the R project directly from code.<br />
<br />
I've been using this for some time but decided it was time to share with everyone else. So I put together a simple demo application that shows how to access mt4R.dll in a simple VB6 form application.<br />
<br />
You can download <a href="https://sites.google.com/site/marketformula/vb6-to-c/vb6-to-c-downloads/calling-r-from-vb6-vba">Calling R From VB6 VBA</a>. (Please follow the instructions on that page) for use in your own projects.<br />
<br />
A note for VB6 / VBA developers:<br />
<br />
The array structure of R and VB is not the same. Whereas in R the arrays are arranged as:<br />
<br />
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; border: 1px inset; font-size: 13.63636302947998px; height: 34px; overflow: auto; padding: 6px; width: 640px;">A[row, column]</pre>
<br />
In VB6 / VBA the arrays are declared as follows<br />
<br />
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; border: 1px inset; font-size: 13.63636302947998px; height: 34px; overflow: auto; padding: 6px; width: 640px;">Dim A(column, row) as double</pre>
<br />
When transferring this matrix via Rm (the matrix operation) it will send the data in the correct format if the array in VB is declared as above.<br />
<br />
Please let me know if you have any comments, questions or problems getting this code to work.<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0tag:blogger.com,1999:blog-4867375881600669461.post-57588226842248821732012-04-03T10:00:00.000-04:002014-05-12T01:32:31.666-04:00Code to Export C# DLL to MetatraderNote: updated build 600+ code can be found at <a href="http://vb6-to-csharp.blogspot.com/2014/05/code-to-export-c-dll-to-metatrader.html" target="_blank">Code to Export C# DLL to Metatrader Build 600+</a>.<br />
<br />
I worked up a simple sample C# DLL that is properly exported for use with Metatrader. I made use of the template that can be downloaded from <a href="https://sites.google.com/site/robertgiesecke/Home/uploads">C# Project Template for Unmanaged Exports</a>.<br />
<br />
C# Code for "testUMD.dll" below using R. Giesecke's template:<br />
<div style="background-color: #f5f5ff; margin: 5px 20px 20px; text-align: left;">
<div class="smallfont" style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 11px; margin-bottom: 2px;">
Code:</div>
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; border: 1px inset; font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px; height: 498px; overflow: auto; padding: 6px; text-align: left; width: 500px;">using System;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace testUnmanagedDLL
{
class Test
{
[DllExport("AddInteger", CallingConvention = CallingConvention.StdCall)]
public static int AddInteger(int Value1, int Value2) {
MessageBox.Show("Add Integers: " + Value1.ToString() + " " + Value2.ToString());
return (Value1 + Value2);
}
[DllExport("AddDouble", CallingConvention = CallingConvention.StdCall)]
public static double AddDouble(double Value1, double Value2) {
MessageBox.Show("AddDouble: " + Value1.ToString() + " " + Value2.ToString());
double Value3 = Value1 + Value2;
return (Value3);
}
[DllExport("AddDoubleString", CallingConvention = CallingConvention.StdCall)]
public static string AddDoubleString(double Value1, double Value2) {
MessageBox.Show("AddDoubleString: " + Value1.ToString() + " " + Value2.ToString());
double Value3 = Value1 + Value2;
return (Value3.ToString() );
}
[DllExport("returnString", CallingConvention = CallingConvention.StdCall)]
public static string returnString(string Input) {
MessageBox.Show("Received: " + Input);
return ("SEND to MT4");
}
// many thanks to anonymous for the code sample below!
[DllExport("ReturnDouble2", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static double ReturnDouble2() {
return 4.5;
}
}</pre>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
<br /></div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
<br /></div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
<span style="background-color: #f5f5ff; font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px; text-align: left;">MT4 Script 'testDLL' code below: File testUMD.dll added to experts/libraries folder</span></div>
<div style="background-color: #f5f5ff; margin: 5px 20px 20px; text-align: left;">
<div class="smallfont" style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 11px; margin-bottom: 2px;">
Code:</div>
<pre class="alt2" dir="ltr" style="background-color: #e1e4f2; border: 1px inset; height: 402px; overflow: auto; padding: 6px; width: 500px;">#import "testUMD.dll"
int AddInteger(int Value1, int Value2);
double AddDouble(double Value1, double Value2);
string AddDoubleString(double Value1, double Value2);
string returnString(string Input);
double ReturnDouble2();
#import
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
Print("AddInteger: " + AddInteger(250, 750));
double a = AddDouble(250,750);
Print("AddDouble: " + NormalizeDouble(a,4));
double d = StrToDouble(AddDoubleString(250, 750));
Print("AddDoubleString: " + NormalizeDouble(d,4));
string temp = "Send to DLL";
string recv = returnString(temp);
Print(recv);
double dd = ReturnDouble2();
Print("Returning Double from C#: " + NormalizeDouble(dd, 4));
//----
return(0);
}</pre>
</div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
<br /></div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
<span style="background-color: #f5f5ff; font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px; text-align: left;">Cursory Summary: Integer passing = success, double passing MT4 to C# = success, double passing from C# to MT4 = fail, string passing = success. I haven't experimented with arrays. Sample code written with VS 10 .NET 4.0.</span></div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
<br /></div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
<span style="background-color: #f5f5ff; font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px; text-align: left;">If anyone knows how to </span>successfully get doubles to pass from C# to MT4 without conversion to a string, please leave a comment!</div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
<br /></div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
------------</div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
Edit: thanks for the feedback from anonymous! The code has been updated to reflect passing a double from C# to Metatrader.</div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
<br /></div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
By the way, you must use the 32 bit version of the DLL. The 64 bit version and the "Any CPU" version both failed with error #127 in Metatrader. This is understandable considering MT4 is a 32 bit program. </div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
<br /></div>
<div style="font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; font-size: 13px;">
As per g3ro's suggestion I have made available for download both the testUnamanagedDLL Visual Studio solution and the testDLL MT4 script. <a href="https://sites.google.com/site/marketformula/vb6-to-c/vb6-to-c-downloads/code-to-export-c-dll-to-metatrader">Download testUnmanagedDLL VS solution</a></div>
</div>
<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com71tag:blogger.com,1999:blog-4867375881600669461.post-63040762194853635632012-04-02T19:27:00.000-04:002012-04-02T19:27:02.326-04:00Export C# DLL to MetatraderI've recently learned several methods for exporting a C# DLL for use outside .NET and specifically to Metatrader. The first method was alluded to in the article: <br />
<a href="http://vb6-to-csharp.blogspot.com/2011/08/write-csharp-c-dll-for-metatrader.html">Write CSharp (C#) DLL for Metatrader</a>.<br />
<br />
This is a template created to make things simpler.<br />
<br />
<a href="https://sites.google.com/site/robertgiesecke/Home/uploads#TOC-Samples">C# Project Template for Unmanaged Exports</a><br />
<br />
The template method works but you have to delete the default function and use a slightly different syntax. (see next post).<br />
<br />
I've seen two other articles that I haven't yet had time to fully explore but that I've heard work for simplifying the export of a C# DLL.<br />
<br />
<a href="http://www.codeproject.com/Articles/37675/Simple-Method-of-DLL-Export-without-C-CLI">Simple Method of DLL Export without C++/CLI</a><br />
<br />
<a href="http://www.codeproject.com/Articles/16310/How-to-Automate-Exporting-NET-Function-to-Unmanage">How to Automate Exporting .NET Function to Unmanaged Programs</a><br />
<br />
This second article looks not too difficult and I've heard good feedback on its implementation.<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0tag:blogger.com,1999:blog-4867375881600669461.post-37800628776295654802011-10-18T16:14:00.000-04:002011-10-23T16:44:02.451-04:00Misc VB6 to C# Commands<b style="background-color: transparent;"><span style="font-size: large;">Quick reference VB6 to C#</span></b><br />
<br />
Q: <b>How do you replicate VB6's Debug.Print in C#?</b><br />
A: In C#, Add <b>using System.Diagnostics;</b> to the top of the project. Then it is possible to use:<br />
<br />
Debug.Print("debug text");<br />
Debug.Write("writes without adding the newline character");<br />
Debug.WriteLine("writes with adding the newline character");<br />
<br />
All three methods write to the Immediate window in C# just as Debug.Print does in VB6.<br />
<br />
---------------------------------------------------------------- <br />
Q: <b>How do you replicate the VB6 mid$ function in C#</b>?<br />
VB6: mid$("ABCDEFG12345", 7, 2)<br />
returns "G1"<br />
<br />
C# Debug.Print("ABCDEFG1234".Substring(6, 2));<br />
returns "G1"<br />
(note how in VB6 strings the first string's (A in the string above) reference is 1, while in C# the first string's reference is 0.)<br />
----------------------------------------------------------------<br />
Q: <b>How do you call a routine in C# or why do I get the error: </b><br />
<br />
Only assignment, call, increment, decrement, and new object expressions can be used as a statement<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<div><br />
</div><br />
VB6: Call myRoutine or<br />
myRoutine<br />
<br />
<span style="background-color: transparent;">C#: myRoutine(); // you must add the () at the end of the routine in C#!</span><div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0tag:blogger.com,1999:blog-4867375881600669461.post-79925664988065187442011-08-18T07:00:00.004-04:002011-08-18T07:00:12.379-04:00MT4 to R ProjectI stumbled upon an interesting interface written to connect Metatrader (MT4) to the <a href="http://www.r-project.org/">R project for statistical computing</a>. If you have an active R installation, you can access R through MT4 via the mt4R.dll. mt4R.dll was created as an interface to wrap the functions of Rterm.exe, a component of the R project that is meant to allow batch mode access to the R terminal. mt4R.dll is a wrapper for Rterm.exe that exposes the R functionality in a well documented and intuitive manner.<br />
<br />
Metatrader is a charting package for trading forex. If you like Metatrader, you will like the <a href="https://sites.google.com/site/prof7bit/r-for-metatrader-4">R for MetaTrader</a> project, where you can download mt4R.dll as well as sample MT4 code to interface MT4 with R. There is a discussion about R for Metatrader on <a href="http://www.forexfactory.com/showthread.php?t=260422">Forex Factory</a>.<br />
<br />
I plan to use mt4R.dll to interface VB6 to R, thus saving me from having to implement my own interface. In this effort I have found partial success, though I'm still struggling with a matrix conversion issue of the original interface, and may post more on a VB6 wrapper for mt4R.dll as time goes by.<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0tag:blogger.com,1999:blog-4867375881600669461.post-24239923320316090322011-08-02T07:00:00.000-04:002012-09-04T09:19:44.264-04:00Write C# DLL for Metatrader (CSharp)Those C# developers who would like to write a DLL in C# for Metatrader instead of in C++ now have a path to that end. There is a very interesting article titled "Exposing C# code to MQL5 using unmanaged exports" that I've just read. I use MT4 (MQL4) instead but the idea is still valid.<br />
<br />
Read/skim the article and read section 2.5 onward.<br />
<a href="http://www.mql5.com/en/articles/249">Exposing C# code to MQL5 using unmanaged exports - MQL5 Articles</a><br />
<br />
Read the directions, then download the Template for C# "Unmanaged Export Library" and place the zip file in the right directory (by following the directions on that page):<br />
<a href="https://sites.google.com/site/robertgiesecke/Home/uploads#TOC-Samples">C# Project Template for Unmanaged Exports</a><br />
<br />
Load Microsoft Visual Studio 2010 (or Microsoft Visual C# 2010 Express) and select the "Unmanaged Export Library" template. Follow the code samples. Hope this helps somebody!<br />
<br />
You can find <a href="http://vb6-to-csharp.blogspot.com/2012/04/code-to-export-c-dll-to-metatrader.html">sample code for creating a C# dll with the Unmanaged Export Library here </a> including a download for the visual studio solution and the MT4 sample script.<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com7tag:blogger.com,1999:blog-4867375881600669461.post-56575082531266646832011-08-01T14:59:00.002-04:002011-08-07T22:30:28.478-04:00How To Write a C# 2010 DLL and Call It Within VB6 - CSharp InteroperabilityInteroperability in C# is a real PITA. I know because I just spent the entire day chasing down a simple example. Unfortunately the C# documentation out there is so sparse and out of date (in this area the C# language seems to have changed quite a bit pre 2010) on the subject that doing a simple task like linking a C# dll from VB6 seems next to impossible. Maybe the topic is so mind numbingly simple that only pure C# neophytes struggle with something so mundane. But there is hope at the end of this rainbow. This short tutorial will give you the code necessary to write a simple C# 2010 DLL, and link that DLL via COM in VB6.<br />
<br />
C# code:<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">using System;</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">using System.Collections.Generic;</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">using System.Linq;</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">using System.Text;</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">using System.Runtime.InteropServices;</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">namespace testMath</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">{</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> public interface Math</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> {</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> int Multiply(int x, int y);</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> int Add(int x, int y);</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> [ClassInterface(ClassInterfaceType.None)]</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> public class Calc : Math</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> {</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> public int Multiply(int x, int y)</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> {</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> return(x * y);</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> public int Add(int x, int y)</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> {</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> return (x + y);</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">}</span><br />
The public interface is what is shown in VB6 when you look at the referenced class's methods and properties. If the interface is excluded, the class shows up as not having any way to access the methods (interface-less).<br />
<br />
The only real kicker is the <b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">[ClassInterface(ClassInterfaceType.None)]</span></b> line that eliminates extraneous class interfaces, including the desired Multiply and Add functions from showing up in the interface. You can verify this by making the removing "public" from in front of the interface declaration.<br />
<br />
However, because a public interface is declared with Multiply and Add, those interface elements show up in VB6 as if they were the actual functions, and because the class that inherits the "<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><b>: Math</b></span>" interface also contains the Multiply and Add functions, VB6 is none the wiser.<br />
<br />
On the AssemblyInfo.cs page make sure you see the following line:<br />
<b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">[assembly: ComVisible(true)]</span></b><br />
<br />
If it is set to false, make the change. This can also be done from within the Visual Studio environment under the Project/Properties menu. Choose to "Register for COM interop" on the Build tab, and on the Application tab under Assembly Information, make sure to check that "Make assembly COM-Visible" is checked.<br />
<br />
Note: the C# DLL was saved as testClass.dll.<br />
<br />
<br />
VB6 code:<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Option Explicit</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Private o As testClass.Calc</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Private Sub Form_Load()</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> Set o = New testClass.Calc</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> Debug.Print "testClass.Calc"</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> Debug.Print o.Add(5, 10)</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> Debug.Print o.Multiply(5, 5)</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> Set o = Nothing</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">End Sub</span><br />
<br />
Yes the VB6 end of the equation really is that simple. In the VB6 IDE, just add the reference to the .tlb that was created in C# under Project/References (menu) and you're good to go.<br />
<div><br />
</div><div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0tag:blogger.com,1999:blog-4867375881600669461.post-6355069518445637712011-08-01T00:14:00.000-04:002011-08-01T00:14:15.614-04:00C# BooksI'm reading the following two books to learn C#.<br />
<br />
<u>Visual C# 2010 Step by Step</u> by John Sharp. I usually don't like the step by step books but actually found this book an easy and clear read right from the beginning. More so than my other selection. The book is divided into sections.<br />
<br />
Part I contains chapters 1-6 and introduces C# and Visual Studio 2010.<br />
Part II is chapters 7-14 and is titled "Understanding the C# Language."<br />
<br />
I'm just starting chapter 13, "Creating Interfaces and Defining Abstract Classes." The book was fairly clear up through chapter 12. I needed some more in-depth analysis of the C# language, so I started a second book.<br />
<br />
<u>Beginning Visual C# 2010</u> from Wrox press. I've read and liked other Wrox press books before and so I had high expectations for this book. Unfortunately I didn't have a good experience in the early chapters. The book is written in a very loose "conversational" style that drives me crazy. I also thought that the book started covering the wrong material, or the right material in the wrong order. This led me to start reading the "Step by Step" book above.<br />
<br />
However, after plowing through 12 1/2 chapters of the "Step by Step" book I needed something more thorough. I came back to the Wrox book and found that if anything, this book is thorough. The chapters are longer and they don't revolve around a particular code sample as the "Step by Step" book does, but overall I found reading these books in this order to be helpful and would suggest this approach.<br />
<br />
By working through the examples in the "Step by Step" book and manually typing in the code I was able to learn much about the Visual Studio 2010 IDE, some of the C# features and this was useful for me to be led through the samples. I find that working through a specific problem tends to help me the most, particularly when dealing in abstract concepts. It also helps if the examples are relevant to a real-world problem, but that's asking quite a lot from books of this sort.<br />
<br />
I'm in the middle of chapter 11, "Collections, Comparisons, and Conversions" in the Wrox book. Part I of the Wrox book covers chapters 1-14 and is titled "The C# Language." Part I in the Wrox book covers approximately the same material as in the "Step by Step" book, though with a lot more detail. Case in point, I'm on page 253 and Chapter 13 of "Step by Step" but on page 314 and chapter 11 of "Beginning Visucal C# 2010."<br />
<br />
I wouldn't consider either as a great book but both were available at the public library.<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0tag:blogger.com,1999:blog-4867375881600669461.post-18608641287965995412011-07-31T23:44:00.001-04:002012-09-04T09:20:26.276-04:00VB6 to C# (CSharp) - The Journey Begins!As a long time Visual Basic 6 (VB6) developer, I have put off transitioning from VB6 to C# (C Sharp) until now. Now seems to be the right time to make the gradual transition to C# due to my need for a true multi-core programming solution and the feeling that it's just time to update my skills. This blog will chronicle my journey.<br />
<br />
As a VB6 user, why have I chosen to learn C# and not VB.NET? After evaluating the .NET framework and learning that VB.NET really is a totally different language, and that VB.NET does not have the ability to write unmanaged code I started looking at C#. I've been reading the Windows API documentation for years and as a result have some familiarity with C. I have also done some work in a couple of C-like scripting languages, including MQL4 for Metatrader. I really like the tight, compact syntax of C, but also like having a managed environment, which rules out C++. The quirkiness of C++ is also a turn off. I also felt that learning C# would be a better way to round out my development skill set and to make myself more marketable. Since I already know VB6, after learning the ins and outs of C#, I feel it will be fairly straightforward to code in VB.NET if need be.<br />
<br />
I consider my VB6 level of proficiency to be expert (modesty). I regularly use Windows APIs to enhance the speed and capability of VB6. I don't write my own type libraries or anything crazy like that, but I have found that there are few problems that can't be solved with VB6. That being said, since starting this journey learning C#, my eyes have been opened to how VB6 is really a subset of a full or complete programming language. I won't call it a toy programming language but perhaps a dwarf is a more accurate term. That being said, I still enjoy coding in VB6 and plan to make use of both technologies, while upgrading new development to C#.<br />
<br />
Thanks for coming along for the ride. I hope we both learn something!<div class="blogger-post-footer"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22429287-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></div>Patrick Whitehttp://www.blogger.com/profile/16029754567005056050noreply@blogger.com0