<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="generator" content="Adobe RoboHelp 2019" />
<title>Note of Using Visual C#</title>
<link rel="StyleSheet" href="../../../../../ms_help.css" type="text/css" />
 <script type="text/javascript" language="JavaScript">
//<![CDATA[
function reDo() {
  if (innerWidth != origWidth || innerHeight != origHeight)
     location.reload();
}
if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
	origWidth = innerWidth;
	origHeight = innerHeight;
	onresize = reDo;
}
onerror = null; 
//]]>
</script>
<style type="text/css">
<!--
div.WebHelpPopupMenu { position:absolute;
left:0px;
top:0px;
z-index:4;
visibility:hidden; }
p.WebHelpNavBar { text-align:right; }
-->
</style>

<script type="text/javascript" src="../../../../../template/scripts/rh.min.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/common.min.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/topic.min.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/constants.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/utils.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/mhutils.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/mhlang.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/mhver.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/settings.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/XmlJsReader.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/loadparentdata.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/loadscreen.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/loadprojdata.js"></script>
<script type="text/javascript" src="../../../../../template/scripts/mhtopic.js"></script>
 <link rel="stylesheet" type="text/css" href="../../../../../template/styles/widgets.min.css">
 <link rel="stylesheet" type="text/css" href="../../../../../template/styles/topic.min.css">
<script type="text/javascript" >
gRootRelPath = "../../../../..";
gCommonRootRelPath = "../../../../..";
gTopicId = "6.1.1.2.3.0_2";
</script>
 <meta name="brsprev" value="sdk/windows_api/tutorial/common/notes/note_visual_basic.htm">
 <meta name="brsnext" value="sdk/windows_api/tutorial/using_event/using_event.htm">
 <meta name="topic-breadcrumbs" content="C-LOGGER SDK > Windows API > Tutorial > Common Processing > Note of Using Each Language" />
</head>

<body>
<script type="text/javascript" src="../../../../../ehlpdhtm.js"></script>

<!-- Google Tag Manager (noscript) -->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-P45RPFN" style="width: 0px; 
		 height: 0px; display: none; visibility: hidden;">
 <p>&#160;</p>
</iframe>
</noscript>
<!-- End Google Tag Manager (noscript) -->


<div><script type="text/javascript" language="javascript">//<![CDATA[
document.write("<p  style=\"text-align:left;\" class=\"breadcrumbs\">");
AddMasterBreadcrumbs("../../../../../c_logger.htm", "breadcrumbs", " &gt; ", "Home", "../../../../../welcome/c_logger.htm");
document.write("<a class=\"breadcrumbs\" href=\"../../../../welcome/c_logger_sdk.htm\">C-LOGGER SDK<\/a>  &gt;  <a class=\"breadcrumbs\" href=\"../../../windows_api.htm\">Windows API<\/a>  &gt;  <a class=\"breadcrumbs\" href=\"../../tutorial.htm\">Tutorial<\/a>  &gt;  <a class=\"breadcrumbs\" href=\"../common_processing.htm\">Common Processing<\/a>  &gt;  <a class=\"breadcrumbs\" href=\"note_visual_basic.htm\">Note of Using Each Language<\/a>  &gt;  Note of Using Visual C#<\/p>");
//]]></script>
</div>

<h1>Note of Using Visual C#</h1>
<h2>Function specifications</h2>
<p style="margin-left: 40px;">The class library is being offered as an 
 interface for C#.<br />
The driver functions are called from the methods of the class library.<br />
The methods in the class library are defined in the form of removing the 
 prefix of original functions.<br />
Please call the method with the name that does not contain the prefix of 
 original function.</p>
<p style="margin-left: 40px;">For example, when you want to call the LoggerOpenApplication 
 function</p>
<p class="code" style="margin-left: 80px;">Ret = logger.OpenApplication();</p>
<p style="margin-left: 40px;">* Not compatible with Universal Windows Platform 
 (UWP)</p>
<h2>&#160;</h2>
<h2>Function parameters and return value</h2>
<p style="margin-left: 40px;">The contents of the parameters and the return 
 value of functions are common regardless of the development language.<br />
Please refer to the function reference for details.</p>
<h2>&#160;</h2>
<h2>Note of using callback function</h2>
<p style="margin-left: 40px;">When notifying an event by using callback 
 function in Visual C#, it is required to fix the callback function's memory 
 address.<br />
<br />
The following code is the sample to process the analog input event that 
 device operation end.<br />
For details, please refer to the sample programs.</p>
<p style="margin-left: 40px;"><font 
 face="Courier New">■</font> Declaring as global variables.</p>
<p class="code" style="margin-left: 80px;">GCHandle gCh;<br />
PLOGGEREVENTCALLBACK &#160;pdelegate_func;<br />
IntPtr pfunc;</p>
<p style="margin-left: 40px;"><font 
 face="Courier New">■</font> In the Load method, initializing 
 the delegate for interrupt process, and add a reference to prevent garbage 
 collection from being destroyed.</p>
<p class="code" style="margin-left: 80px;">pdelegate_func = new PLOGGEREVENTCALLBACK(CallBackProc);<br />
gCh = GCHandle.Alloc(pdelegate_func);</p>
<p style="margin-left: 40px;"><font 
 face="Courier New">■</font> In the Close method, releasing 
 the handle.</p>
<p class="code" style="margin-left: 80px;">gCh.Free();</p>
<p style="margin-left: 40px;"><font 
 face="Courier New">■</font> Retrieving the fixed function 
 pointer.</p>
<p class="code" style="margin-left: 80px;">pfunc = Marshal.GetFunctionPointerForDelegate(pdelegate_func);</p>
<p style="margin-left: 40px;"><font 
 face="Courier New">■</font> Specifying the retrieved 
 fixed pointer by function LoggerSetNotifyEvent.</p>
<p class="code" style="margin-left: 80px;">Ret = logger.SetNotifyEvent(Id, 
 pfunc, (uint)CLoggerConst.LOGGER_PARAM_EVENT_DATANUM, null);</p>
<p>&#160;</p>
<h2>Convert a string variable to a Byte array</h2>
<p style="margin-left: 40px;">The fifth(5) argument to <a href="../../../function_reference/acquisition_settings/logger_set_channel_setting.htm">LoggerSetChannelSetting()</a> 
 function, ChannelName, is a Byte array.<br />
Therefore, you can not use a string variable for parameter of ChannelName 
 directly.<br />
You must convert a string variable to a Byte array before.</p>
<p style="margin-left: 40px;">The following code example shows how to convert 
 a string variable to a Byte array.<br />
See the sample program for details.</p>
<p style="margin-left: 40px;">&#160;</p>
<p style="margin-left: 40px;">■Declare a Byte array and an Encoding class.</p>
<p class="code" style="margin-left: 64px;">string ChName;<br />
Encoding Enc;</p>
<p class="code" style="margin-left: 64px;">&#160;</p>
<p style="margin-left: 40px;">For more information on Encoding class, see 
 Microsoft Web site.</p>
<p style="margin-left: 40px;">System.Text.Encoding Text.Encoding Class: 
 <a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding">https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding</a></p>
<p style="margin-left: 40px;">&#160;</p>
<p style="margin-left: 40px;">■Converts the string &quot;Channel0&quot; 
 to a Byte array, given the code page identifier &quot;Windows-1252&quot;.</p>
<p class="code" style="color: 透明; margin-left: 64px;"><span style="color: 透明;"><span 
	 style="color: 透明;">byte SearchByte = 0;<br />
int Length;<br />
</span></span></p>
<p class="code" style="margin-left: 64px;">Length = Array.IndexOf(ChannelName, 
 SearchByte);</p>
<p class="code" style="margin-left: 64px;">&#160;</p>
<p style="margin-left: 40px;">For more information about the GetEncoding 
 and GetBytes methods, see the Microsoft Web site.</p>
<p style="margin-left: 40px;">Encoding.GetEncoding Method: <a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencoding">https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencoding</a><br />
Encoding.GetBytes Method: <a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytes">https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytes</a><br />
Code page identifiers: <a href="https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers">https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers</a></p>
<p style="margin-left: 40px;">&#160;</p>
<h2>Convert a Byte array to a string variable</h2>
<p style="margin-left: 40px;">The fifth(5) argument to <a href="../../../function_reference/acquisition_settings/logger_get_channel_setting.htm">LoggerGetChannelSetting()</a> 
 function, ChannelName, is a Byte array.<br />
Therefore, you can not use ChannelName as a string variable directly.<br />
You must convert a Byte array to a string variable before.</p>
<p style="margin-left: 40px;">The following code example shows how to convert 
 a Byte array into a string variable ChName.<br />
See the sample program for details.</p>
<p style="margin-left: 40px;">■Declare a string variable and an encoding 
 class.</p>
<p class="code" style="color: 透明; margin-left: 64px;">string ChName;<br />
Encoding Enc;</p>
<p class="code" style="color: 透明; margin-left: 64px;">&#160;</p>
<p class="code" style="margin-left: 40px;">For more information on Encoding 
 class, see Microsoft Web site.</p>
<p style="margin-left: 40px;">System.Text.Encoding Text.Encoding Class: 
 <a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding">https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding</a></p>
<p style="margin-left: 40px;">&#160;</p>
<p style="margin-left: 40px;">■Search from the beginning of the ChannelName 
 array to the terminating character &quot;\0&quot; to get Length as well 
 as the number of valid characters.</p>
<p class="code" style="color: 透明; margin-left: 64px;"><span style="color: 透明;"><span 
	 style="color: 透明;">byte SearchByte = 0;<br />
int Length;<br />
</span></span></p>
<p class="code" style="margin-left: 64px;">Length = Array.IndexOf(ChannelName, 
 SearchByte);</p>
<p style="margin-left: 40px;">For more information on Array class andIndexOf 
 method, see Microsoft Web site.</p>
<p style="margin-left: 40px;">System.Array class: <a href="https://learn.microsoft.com/en-us/dotnet/api/system.array">https://learn.microsoft.com/en-us/dotnet/api/system.array</a><br />
Array.IndexOf method: <a href="https://learn.microsoft.com/en-us/dotnet/api/system.array.indexof">https://learn.microsoft.com/en-us/dotnet/api/system.array.indexof</a></p>
<p>&#160;</p>
<p style="margin-left: 40px;">■Converts a Byte array ChannelName to a string 
 variable ChName, given the code page identifier &quot;Windows-1252&quot;.</p>
<p class="code" style="color: 透明; margin-left: 64px;">Enc = System.Text.Encoding.GetEncoding(&quot;Windows-1252&quot;);</p>
<p class="code" style="margin-left: 64px;">ChName = Enc.GetString(ChannelName, 
 0, Length);</p>
<p style="margin-left: 40px;">For more information about GetEncoding and 
 GetString methods, see Microsoft Web site.</p>
<p style="margin-left: 40px;">Encoding.GetEncoding Method: <a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencoding">https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencoding</a><br />
Encoding.GetString Method: <a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getstring">https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getstring</a><br />
Code page identifiers: <a href="https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers">https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers</a></p>
<p>&#160;</p>
<p>&#160;</p>
<div style="width: 100%; position: relative;" id="footer">
	<hr style="float: aligncenter; " />
	<p>This website uses cookies. By continuing to browse our site you 
	 agree to our <a href="https://www.contec.com/privacy#anc-01">use of 
	 cookies</a>.</p>
</div>
</body>
</html>
