0

Error 203 with kernel32.dll when creating a file

I am trying to use kernel32.dll to create a file into which I can write some results from a MET/CAL Procedure. MET/CAL cannot create or delete files inherently so I am trying to use the kernel32,dll to accomplish this task, then using MATH FSC function REPLACE to write the data to the file.

The attached code is what I have written. I made a struct, per Microsoft's instructions for the SECURITY_ATTRIBUTES  argument, but it can be NULL, so I haven't assigned values to the fields. When I attempt to debug this section, I get the error "Preceding error caused termination of LIB statement" on line 1.048. If I reduce the number of arguments until this error is not produced, the LIB statement executes, but doesn't produce the desired results. I added the function "GetLastError" to the kernel32.dll definition to check what errors are being thrown. It always produces error 203
 
ERROR_ENVVAR_NOT_FOUND

The system could not find the environment option that was entered.

203 (0xCB)
 
 
 

It does this for other functions as well, such as "copyfile" and "deletefile". I can use kernel32.dll for functions "getcomputername", "beep", "getlocaltime", etc. just fine, but anything involving files fails. Can anyone provide me with example code for creating files in MET/CAL using kernel32.dll?

 

5 comments

Date Votes
0
Avatar
Samuel Anderson

Image did not attach in original post.

Attachment not imported: capture.png
0
Avatar
Chad D.

Hi Samuel313, from your attached image, it looks like you are trying to edit the contents of an ini file.  MET/CAL's MATH FSC provides functions for reading and writing values to ini files, working with CSV files, and also performing some file I/O operations.  The DOS FSC can also be used to delete files via cmd.exe.  I believe these may be easier to use and maintain than attempting to replicate the functionality using the LIB FSC.

The WIF() function will attempt to create the ini file if it does not already exist.  Here is an example of them in use, followed by an example of how to use the DOS FSC to delete a file.

  1.001  MATH         IniFile   = "C:\\temp\\test.ini"
  1.002  MATH         Section   = "test_section"
  1.003  MATH         Parameter = "test_parameter"
  1.004  MATH         Value     = "1.1234"
 
  1.005  MATH         Insert = WIF(IniFile, Section, Parameter, Value)
 
# Delete file.
  1.006  DOS          -u -w cmd /c del "[V IniFile]"

The MATH FSC also provides several functions for working with file I/O.  These are documented int he MATH FSC help topic.  Most functions which write to a file will attempt to create the file if it does not exist.  You can also use MATH FSC funcitons like EXISTS() to determine if a directory or file already exists before attempting to perform I/O on that location.

Hopefully this information is what you are looking for.  Please let us know if you have any questions!

-Chad D.

0
Avatar
Samuel Anderson

Thanks Chad,

The MATH FSC documentation is unclear that the WIF will attempt to create the ini file, but I appreciate your help in letting me know that that is the case. I had intended on including some comments before the sections in the ini file, which cannot be done with the WIF function. I suppose I can create the section header and data first with WIF, and then use INSERT to place the comments ahead of the section headers.

0
Avatar
Chad D.

Hi Samuel313, you are correct on all counts.  I will update the MATH FSC help topic to reflect which functions will attempt to create the file if it does not exist.  It sounds like you are doing some pretty fun stuff in your procedures!  Let us know if we can help with anything.

-Chad D.

0
Avatar
Chad D.

I just finished reviewing the functions, and it looks like the MATH WIF() function is the only one that needs to have the documentation clarified.  I will get the details from the developers and add it to the help topic.

Thanks again for bringing this to our attention!

-Chad D.

Please sign in to leave a comment.