{"id":4217,"date":"2014-03-30T09:24:13","date_gmt":"2014-03-30T09:24:13","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/opening-a-file-in-my-vc-application-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:24:13","modified_gmt":"2014-03-30T09:24:13","slug":"opening-a-file-in-my-vc-application-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/opening-a-file-in-my-vc-application-collection-of-common-programming-errors\/","title":{"rendered":"opening a file in my VC++ application-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn Hi ,i am new to VC++.now i want to open a .xml file in my application.if i opened it,others\u00a0should not be able to\u00a0open it.i gave the following code,but it is showing error at runtime.<\/p>\n<p>LPOFSTRUCT pStruct;<\/p>\n<p>HFILE hh;<br \/>\nhh=OpenFile(&#8220;new.xml&#8221;,pStruct,OF_SHARE_DENY_WRITE);<\/p>\n<p>help me to solve it please&#8230;.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn1 I think you are looking at the wrong function, see link:<br \/>\nhttp:\/\/msdn.microsoft.com\/en-us\/library\/bb540534(VS.85).aspx<\/p>\n<table>\n<tr>\n<td>HANDLE\u00a0hFile\u00a0=\u00a0CreateFile(_T(&#8220;my.xml&#8221;),GENERIC_READ,0,NULL,\u00a0 \u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,\u00a0NULL);\u00a0 \u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0 \u00a0<\/td>\n<\/tr>\n<tr>\n<td>if\u00a0(hFile\u00a0==\u00a0INVALID_HANDLE_VALUE)\u00a0\u00a0{ \u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0printf(&#8220;Failed\u00a0to\u00a0open\u00a0file\\n&#8221;);\u00a0 \u00a0<\/td>\n<\/tr>\n<tr>\n<td>}\u00a0else\u00a0{ \u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\/\/\u00a0do\u00a0reading..\u00a0 \u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0CloseHandle(hFile);\u00a0 \u00a0<\/td>\n<\/tr>\n<tr>\n<td>}\u00a0<\/td>\n<\/tr>\n<\/table>\n<p>iv<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn2 hithank you&#8230;<\/p>\n<p>i&#8221;l check it&#8230;.<\/p>\n<p>Regards, L.Tony<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>msdn Hi ,i am new to VC++.now i want to open a .xml file in my application.if i opened it,others\u00a0should not be able to\u00a0open it.i gave the following code,but it is showing error at runtime. LPOFSTRUCT pStruct; HFILE hh; hh=OpenFile(&#8220;new.xml&#8221;,pStruct,OF_SHARE_DENY_WRITE); help me to solve it please&#8230;. msdn1 I think you are looking at the wrong [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4217","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4217"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4217\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}