Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Win32API from cobol

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,
Can anyone tell me how to use Win32Api in cobol, I am using Fujitsu Cobol.
What I am trying to do is use CreateDirectory Function. Can anyone tell me how to use that.
Following is what Win32Api help file says
BOOL CreateDirectory(

LPCTSTR lpPathName, // pointer to a directory path string
LPSECURITY_ATTRIBUTES lpSecurityAttributes // pointer to a security descriptor
);


Parameters

lpPathName

Points to a null-terminated string that specifies the path of the directory to be created.

There is a default string size limit for paths of MAX_PATH characters. This limit is related to how the CreateDirectory function parses paths.
Windows NT: An application can transcend this limit and send in paths longer than MAX_PATH characters by calling the wide (W) version of CreateDirectory and prepending "\\?\" to the path. The "\\?\" tells the function to turn off path parsing; it lets paths longer than MAX_PATH be used with CreateDirectoryW. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "
\\?\UNC\bill_g_1\hotstuff\coolapps" is seen as "\\bill_g_1\hotstuff\coolapps".

lpSecurityAttributes

Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpSecurityAttributes is NULL, the handle cannot be inherited.

Windows NT: The lpSecurityDescriptor member of the structure specifies a security descriptor for the new directory. If lpSecurityAttributes is NULL, the directory gets a default security descriptor. The target file system must support security on files and directories for this parameter to have an effect.
Windows 95: The lpSecurityDescriptor member of the structure is ignored.
===========================================================
My problem is I don't know how to point to SECURITY_ATTRIBUTES Structure Can anyone help. The Security Attribute structre is declared as follows.

typedef struct _SECURITY_ATTRIBUTES { // sa
DWORD nLength;
LPVOID lpSecurityDescriptor;
BOOL bInheritHandle;
} SECURITY_ATTRIBUTES;

I couldn't find any information anywhere. Please help.
Thanks .
 
Fujitsu Cobol has 2 routines to do this:
1. CALL "CBL_CREATE_DIR" USING (a pic x(..) field containing the name of the directory terminated by a space or binary zero)
2. If the directory name should contain one or more spaces:
CALL "CBL_CREATE_DIR2" USING (a pic x(..) field containing the name of the directoy terminated by a binary zero)

If you want to use the Win32 API CreateDirectory: There are two versions of this one, the ANSI version is CreateDirectoryA, you should use this name. The second parameter can be omitted, a null pointer should be passed. A null pointer can be passed by coding "BY VALUE 0". The statement would be: CALL "CreateDirectoryA" USING BY REFERENCE (a null-terminated pic x(..) field) BY VALUE 0.

If you do want to pass the SD, code it like this:
01 SEC-ATTR.
03 NLENGTH PIC 9(09) COMP-5.
03 SEC-DESC POINTER.
03 BINH-H PIC 9(09) COMP-5.
and pass it like CALL "CreateDirectoryA" USING BY REFERENCE DIRNAME BY REFERENCE SEC-ATTR.


 
Hello,
Thank you very much for trying to help. I tried both unfortunately it didn't work. I am getting the following error. FYI I am using Fujitsu Cobol Version 3. I don't know if version really matters in using Win32API.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

: error LNK2001: unresolved external symbol _CREATEDIRECTORYA@8
: fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: 'C:\FSC\PCOBOL32\LINK' : return code '0x19'
Stop.

Linking files failed.
Please close the window.
************************************************************
I will keep trying again.
Thanks again.
Saju Ashan.
 
I'm sorry. I have forgotten two things:

1. Use the NOALPHAL compiler option
2. add "WITH PASCAL LINKAGE" to the call-statement, so CALL "CreateDirectoryA" WITH PASCAL LINKAGE USING ....

The compiler generates a warning on the PASCAL LINKAGE clause, saying this is not implemented, but it does work in spite of the warning.

Marcel
 
Hi Marcel,
That worked, NOALPHAL alone will work. Thanks a lot for the help.
Saju Ashan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top