C # SetupCopyOEMInf installs the driver and returns destinationinffilenamecomponent

Source: Internet
Author: User

Recently written in C # to install the USB drive, you must call the API SetupCopyOEMInf:

BOOL WINAPI SetupCopyOEMInf (  _in_       pctstr sourceinffilename,  _in_       pctstr oemsourcemedialocation,  _in_       DWORD Oemsourcemediatype,  _in_       DWORD Copystyle,  _out_opt_  ptstr destinationinffilename,  _in _       DWORD destinationinffilenamesize,  _out_opt_  pdword requiredsize,  _out_opt_  ptstr Destinationinffilenamecomponent);

So in C # it says:

[DllImport ("Setupapi.dll", SetLastError =true)]        Private Static extern BOOLSetupCopyOEMInf (stringSourceinffilename,stringoemsourcemedialocation, Oemsourcemediatype oemsourcemediatype, Oemcopystyle Copystyle,  out stringDestinationinffilename,intDestinationinffilenamesize,intRequiredsize, out stringdestinationinffilenamecomponent);

Where destinationinffilename represents the absolute path of the INF file in the C:\Windows\inf directory after the successful installation of the driver, the INF file name is not the same as the original INF file, but the content is identical, I do not know why the INF driver after the installation of the INF file will be replaced by a name and then copy to the C:\Windows\inf directory? Is there an expert to answer it?

Destinationinffilenamecomponent represents the name of the INF that was copied to the C:\Windows\inf directory, which is useful for calling Setupuninstalloeminf to uninstall the driver when the name is used.

Then I call SetupCopyOEMInf in C #:

 unsafe   {suc Cess  = SetupCopyOEMInf (Infpath, , Oemsourcemediatype.spost_path, Oemcopystyle.sp_copy_newer, out  destinationinffilename, 260   0 , Span style= "color: #0000ff;"            >out   destinationinffilenamecomponent); }

260 is the maximum length of the file directory, view Log,c:\windows\inf\setupapi.dev.log, can be installed successfully, success to true, but the next question bothered me for a long time, Destinationinffilenamecomponent and Destinationinffilename always have no value, according to https://msdn.microsoft.com/en-us/library/ Aa376990.aspx on the words, the successful execution will return these two values, destinationinffilenamecomponent is called Setupuninstalloeminf unload driver must pass parameters, no value can not uninstall, Google has not solved for half a day, finally see The setupcopyoeminf,destinationinffilename written by someone else in C + + is a TCHAR array of length 260, so I changed the SetupCopyOEMInf prototype of C # to:

[DllImport ("Setupapi.dll", SetLastError =true)]        Private Static extern BOOLSetupCopyOEMInf (stringSourceinffilename,stringoemsourcemedialocation, Oemsourcemediatype oemsourcemediatype, Oemcopystyle Copystyle,  out Char[] destinationinffilename,intDestinationinffilenamesize,intRequiredsize, out stringdestinationinffilenamecomponent);

The destinationinffilename is then declared as a 260-length char array, but the call will report the executionexception exception. Later, the prototype parameter char[] Destinationinffilename the front of the out, destinationinffilenamecomponent the value is finally correctly obtained!!!!!!!!

But Destinationinffilename still can't get, at least have a, finally can do uninstall, specific why can also not very clear, why Ptstr Destinationinffilename pass C # string wrong? It is possible to pass a char array, but it is not possible to use out, and it is estimated that Destinationinffilenamecomponent is based on Destinationinffilename. So it's OK to pass a string type of destinationinffilenamecomponent, you're confused!

Ask the great God, in C # How to call SetupCopyOEMInf can correctly get destinationinffilenamecomponent and destinationinffilename these two values!





C # SetupCopyOEMInf installs the driver and returns destinationinffilenamecomponent

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.