<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="topic-comment" content="" />
<meta name="generator" content="Adobe RoboHelp 2019" />
<title>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.2.0_2";
</script>
 <meta name="brsprev" value="sdk/windows_api/tutorial/using_event/callback/visual_basic_dot_net.htm">
 <meta name="brsnext" value="sdk/windows_api/tutorial/using_event/callback/visual_c_mfc.htm">
 <meta name="topic-breadcrumbs" content="C-LOGGER SDK > Windows API > Use Event" />
</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=\"../using_event.htm\">Use Event<\/a>  &gt;  Visual C#<\/p>");
//]]></script>
</div>

<h1>Visual C#</h1>
<h2>Create Callback Function</h2>
<p style="margin-left: 40px;">The callback function has the following format. 
 You can specify any name for this function.</p>
<p class="code" style="margin-left: 80px;">public int CallBackProc(short 
 Id, short Message, int wParam, int lParam, void *Param);</p>
<p style="margin-left: 40px;">[unsafe] keyword is required for any functions 
 dealing with pointers.<br />
Add [unsafe] keyword to the created callback routine.</p>
<p class="code" style="margin-left: 80px;">unsafe public int CallBackProc(short 
 Id, short Message, int wParam, int lParam, void *Param)<br />
{<br />
.<br />
.<br />
.</p>
<h2>&#160;</h2>
<h2>Use Delegate</h2>
<p style="margin-left: 40px;">In Visual C#, please use delegate to handle 
 a function pointer.<br />
The delegate declarations for each callback routine are written in the 
 clogger_api.cs file.</p>
<table style="margin-top: 14pt; margin-left: 80px;" cellspacing="0" width="50%">
	<col style="width: 30.047%;" />
	<col style="width: 69.953%;" />
	<tr>
		<td style="width: 30.047%; vertical-align: TOP; padding-left: 0px; 
			 padding-top: 0px; padding-right: 0px; padding-bottom: 0px;"><p>Notify 
		 Event</p></td>
		<td style="width: 69.953%; vertical-align: TOP; padding-left: 0px; 
			 padding-top: 0px; padding-right: 0px; padding-bottom: 0px;"><p>PLOGGEREVENTCALLBACK</p></td>
	</tr>
</table>
<h2>&#160;</h2>
<h2>Register Callback Function</h2>
<p style="margin-left: 40px;">Please use the following functions to register 
 callback functions.</p>
<table style="margin-top: 14pt; margin-left: 80px;" cellspacing="0" width="50%">
	<col style="width: 30.047%;" />
	<col style="width: 69.953%;" />
	<tr>
		<td style="width: 30.047%; vertical-align: TOP; padding-left: 0px; 
			 padding-top: 0px; padding-right: 0px; padding-bottom: 0px;"><p>Notify 
		 Event</p></td>
		<td style="width: 69.953%; vertical-align: TOP; padding-left: 0px; 
			 padding-top: 0px; padding-right: 0px; padding-bottom: 0px;"><p>LoggerSetNotifyEvent</p></td>
	</tr>
</table>
<h2>&#160;</h2>
<h2>Flow of Registering Callback Function</h2>
<p style="margin-left: 40px;">. Initialize delegate<br />
. Get the GCHandle to prevent the garbage collector from moving the delegate 
 used for interrupt processing<br />
. Get a stable pointer to the delegate used for interrupt processing<br />
. Register the retrieved stable pointer by using functions such as LoggerSetNotifyEvent 
 function<br />
. Release the GCHandle for the delegate used for interrupt processing, 
 when it become unnecessary (for example, when the application terminates)</p>
<p style="margin-left: 40px;">For these specific coding content, please 
 refer to samples and <a href="../../common/notes/note_visual_cs.htm">Note 
 of Using Visual C#</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>
