External Procedure with Windows "Handle" datatype

hi all,
I want to create a external procedure which use windows kerne32.dll library and GetFileSize function which is in dll.
http://msdn.microsoft.com/en-us/library/aa364955(v=vs.85).aspx
as you can see in this link , GetFileSize has two parameter, first one is a HANDLE type, how can I assign this parameter ? String is not working.
DWORD WINAPI GetFileSize(
  __in       HANDLE hFile,
  __out_opt  LPDWORD lpFileSizeHigh
Create Or Replace Function GetSize (FileName Varchar2, P_Value in out pls_integer) Return binary_double As
Language C Library Mylib Name "GetFileSize"
parameters (FileName  by reference String, P_Value int, return double );
Declare
  X1 number ;
  X2 Pls_Integer;
  X Number;
Begin
  x2 := 40000000;
  X1 := Getsize('C:\b.sql', X2);
  X := X1;
  dbms_output.put_line('x: ' ||x);
End;
/I allways getting zero value, file is exists and its size is bigger than zero.
what am i doing wrong?

I don't know, Why you are using kernel32.dll to know the file size. This can be done very easily using UTL_FILE.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE OR REPLACE FUNCTION utl_filesize(pi_dir_name  IN VARCHAR2,
  2                                          pi_file_name IN VARCHAR2)
  3    RETURN NUMBER IS
  4    file_size NUMBER;
  5    blk_size  BINARY_INTEGER;
  6    fexists   BOOLEAN;
  7  BEGIN
  8    UTL_FILE.fgetattr(pi_dir_name,
  9                      pi_file_name,
10                      fexists,
11                      file_size,
12                      blk_size);
13    RETURN file_size;
14  END utl_filesize;
15  /
Function created.
SQL> SELECT utl_filesize('SAUBHIK','test2.csv') "Size in Bytes" FROM dual;
Size in Bytes
           61
SQL> SELECT utl_filesize('SAUBHIK','Winter.jpg') "Size in Bytes" FROM dual;
Size in Bytes
       105542
SQL> Now, coming to your actual question.
This is a demo, How to call kernel32.dll from PL/SQL.*
By the way, I have copied kernel32.dll from C:\WINDOWS\system32 to C:\oracle\product\10.2.0\db_3\bin
My listener.ora setup
SID_LIST_LISTENEREXTPROC =
  (SID_LIST =
    (SID_DESC =
      (PROGRAM = extproc)
      (ENV = "EXTPROC_DLLS=ONLY:C:\oracle\product\10.2.0\db_3\bin\kernel32.dll")
      (SID_NAME = extproc)
      (ORACLE_HOME = C:\oracle\product\10.2.0\db_3)
  )My tnsnames.ora setup
EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
  )A little verification.
LSNRCTL> stop  LISTENEREXTPROC
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=extproc)))
The command completed successfully
LSNRCTL> start LISTENEREXTPROC
Starting tnslsnr: please wait...
TNSLSNR for 32-bit Windows: Version 10.2.0.3.0 - Production
System parameter file is C:\oracle\product\10.2.0\db_3\network\admin\listener.o
a
Log messages written to C:\oracle\product\10.2.0\db_3\network\log\listenerextpr
c.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\extprocipc
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=extproc)))
STATUS of the LISTENER
Alias                     LISTENEREXTPROC
Version                   TNSLSNR for 32-bit Windows: Version 10.2.0.3.0 - Prod
ction
Start Date                21-JAN-2011 17:32:26
Uptime                    0 days 0 hr. 0 min. 3 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   C:\oracle\product\10.2.0\db_3\network\admin\listener.
ra
Listener Log File         C:\oracle\product\10.2.0\db_3\network\log\listenerext
roc.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\extprocipc)))
Services Summary...
Service "extproc" has 1 instance(s).
  Instance "extproc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
LSNRCTL> exit
C:\Documents and Settings\Administrator>
C:\>tnsping EXTPROC_CONNECTION_DATA
TNS Ping Utility for 32-bit Windows: Version 10.2.0.3.0 - Production on 21-JAN-2
011 21:53:10
Copyright (c) 1997, 2006, Oracle.  All rights reserved.
Used parameter files:
C:\oracle\product\10.2.0\db_3\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)
(KEY = EXTPROC1))) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO)))
OK (70 msec)
C:\>Now, the actual codes.
SQL> CREATE OR REPLACE LIBRARY kernel32 AS 'C:\oracle\product\10.2.0\db_3\bin\kernel32.dll';
  2  /
Library created.
SQL> CREATE OR REPLACE FUNCTION CreateFile (FileName VARCHAR2 --1
  2                                         ,p_DesiredAccess BINARY_INTEGER --2
  3                                         ,p_ShareMode BINARY_INTEGER --3
  4                                         ,p_SecurityAttributes BINARY_INTEGER --4
  5                                         ,p_CreationDisposition BINARY_INTEGER --5
  6                                         ,p_FlagsAndAttributes BINARY_INTEGER --6
  7                                         ,p_TemplateFile BINARY_INTEGER )--7
  8  Return BINARY_INTEGER
  9   IS EXTERNAL
10  LIBRARY kernel32 Name "CreateFileA"
11  PARAMETERS (FileName STRING 
12              ,p_DesiredAccess long
13              ,p_ShareMode long
14              ,p_SecurityAttributes long
15              ,p_CreationDisposition long
16              ,p_FlagsAndAttributes long
17              ,p_TemplateFile long
18              ,return long );
19  /
Function created.
SQL> /* This is for closing the handle after use. */
SQL> CREATE OR REPLACE FUNCTION CloseFile (p_FileHandle BINARY_INTEGER)
  2                                        Return BINARY_INTEGER
  3   IS EXTERNAL
  4   LIBRARY kernel32 Name "CloseHandle"
  5   PARAMETERS (p_FileHandle long, return long);
  6  /
Function created.
SQL> /* This is the main function for getting size */
SQL> CREATE OR REPLACE FUNCTION GetSize (p_FileHandle BINARY_INTEGER,
  2                                      p_FileSizeHigh IN OUT BINARY_INTEGER)
  3                                      RETURN BINARY_INTEGER
  4   IS EXTERNAL
  5  LIBRARY kernel32 NAME "GetFileSize"
  6  PARAMETERS (p_FileHandle long, p_FileSizeHigh long, return long );
  7  /
Function created.
SQL> set serverout on
SQL> DECLARE
  2    v_FileSize BINARY_INTEGER;
  3    v_FileSizeHigh PLS_INTEGER;
  4    v_FileHandle BINARY_INTEGER;
  5    v_filename VARCHAR2(500) :='C:\test2.csv';
  6    v_dummy BINARY_INTEGER;
  7  BEGIN
  8    v_FileSizeHigh := 400000000;
  9    v_FileHandle:=CreateFile(v_filename -- File name
10                             ,0 -- Type of access required (read/write ect)
11                             ,0 -- disable share mode
12                             ,0 --no securoty attribute
13                             ,3 -- Means Open existing
14                             ,128 --080h, File attribute normal.
15                             ,0); --7
16    v_FileSize := Getsize(v_FileHandle, v_FileSizeHigh);
17    DBMS_OUTPUT.put_line('File Size in Bytes: ' ||v_FileSize);
18    v_dummy:=CloseFile(v_FileHandle);
19  END;
20  /
File Size in Bytes: 61
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL> DECLARE
  2    v_FileSize BINARY_INTEGER;
  3    v_FileSizeHigh PLS_INTEGER;
  4    v_FileHandle BINARY_INTEGER;
  5    v_filename VARCHAR2(500) :='C:\Winter.jpg';
  6    v_dummy BINARY_INTEGER;
  7  BEGIN
  8    v_FileSizeHigh := 400000000;
  9    v_FileHandle:=CreateFile(v_filename -- File name
10                             ,0 -- Type of access required (read/write ect)
11                             ,0 -- disable share mode
12                             ,0 --no securoty attribute
13                             ,3 -- Means Open existing
14                             ,128 --080h, File attribute normal.
15                             ,0); --7
16    v_FileSize := Getsize(v_FileHandle, v_FileSizeHigh);
17    DBMS_OUTPUT.put_line('File Size in Bytes: ' ||v_FileSize);
18    v_dummy:=CloseFile(v_FileHandle);
19  END;
20  /
File Size in Bytes: 105542
PL/SQL procedure successfully completed.
SQL> Verification.
C:\>dir test2.csv
Volume in drive C has no label.
Volume Serial Number is 6806-ABBD
Directory of C:\
12/15/2010  01:35 PM                61 test2.csv
               1 File(s)             61 bytes
               0 Dir(s)   3,405,336,576 bytes free
C:\>dir Winter.jpg
Volume in drive C has no label.
Volume Serial Number is 6806-ABBD
Directory of C:\
10/11/2010  05:27 PM           105,542 Winter.jpg
               1 File(s)        105,542 bytes
               0 Dir(s)   3,405,336,576 bytes free
C:\>

Similar Messages

  • External procedure with Pro*C in it

    I have some C functions that I have compiled into a shared library on Unix.
    One of the functions contains a SQL statement to insert into a table, so I
    compile the file with Pro*C. It compiles fine. I have another C program
    that calls the function within my shared library. It runs fine and the shared
    library does insert the data into the table.
    I create an Oracle library that points to the shared library, then create a stored
    function in the database that executes the routine in the shared library. At
    this point, everything seems in place. We have been using external procedures
    for a while, and they seem to work OK. This is the first one we have, though that
    has Pro*C code in it.
    When I execute the stored function to execute my Pro*C routine, I get the errors
    ORA-06520: PL/SQL: Error loading external library
    ORA-06522: Unresolved external.
    This shared library is the first one that we are using that has Pro*C in it. The
    documentation doesn't say anything about being able to use Pro*C routines
    as external procedures; but it doesn't say you can't. Am I attempting the impossible?
    If not, what am I missing?
    null

    Is your library object pointing to one shared library and in turn function in this library is 'looking' to another shared library? if so, that is not allowed

  • Calling Stored Procedure with Windows Authentication SSIS 2012

    We are upgrading to SQL Server 2012 and our SSIS Packages are failing with: "The operation cannot be started by an account that uses SQL Server Authentication. Start the operation with an account that uses Windows Authentication. Error on line 215:
    (SQR 3913) Could not EXECUTE stored procedure."
    I understand that we need to change over to Windows Authentication but not sure how to authenticate with windows. Our stored procedures are called from an SQR (
    Structured Query Reporter)
    Here is the code:
    begin-procedure Download-Data
    EXECUTE DO=LT_REPORT_SSIS_MSG
    LT_INTERFACE..LT_AR_CUSTOMER_SSIS $business_unit
    INTO &SSIS_MSG char(120)
    end-procedure Download-Data
    Any help would be greatly appreciated!

    The question is how SQR allows it. Thus it becomes not SSIS related
    Arthur My Blog

  • External HDDs With Windows XP SP2

    Hello, Tomorrow I will be installing Windows XP on both of my macs (both run 10.5.2). I have 3 external HDDs connected to one of them, two of which use USB and one Firewire 800 (one of the USB HDDs is formated in FAT32 and the rest of the HDDs in Mac OS Extended Journaled). My question is, when I boot into Windows XP, will XP be able to see the HDDs Formated in Mac OS Extended and if so will it complain that they need reformatting? I never disconnect them, so will this be a problem?

    Welcome to the Apple Forums:
    P will not see the drive formatted with in OS extended and therefore will not complain about it. You can leave them connected while in XP.
    One thing I would recommend is that when you are in the process of installing Windows XP via Boot Camp then I would recommend that you remove all external peripherals with the exception of the mouse and keyboard. This will eliminate any possible complications during installation. You can attach all of them once installation of XP is completed.
    Axel F.

  • How to conect to an airport external disk with windows xp

    Hi,
    Please advise how to get access to an external USB drive connected to my Airport Extreme using my laptop with windows XP. Thanks

    Welcome to Apple Support Communities
    If your PC hasn't got a disc drive, download AirPort Utility from the Apple website to set up the AirPort Express > http://support.apple.com/kb/DL1547?viewlocale=es_ES

  • External Hdd with Windows XP Question

    My dad had a desktop pc crash, the hdd is still good but he purchased another pc and I wanted to know how to go about turning that external Hdd into a virtual machine. I usually run paragon to make an image of my hdd. So I was wondering if I needed to get the cables 2 go adapter so I can hook the hdd up via USB and image the disc that way or am I missing an easier way to do this!
    Thanks for all your help!

    Welcome to the Apple Forums:
    P will not see the drive formatted with in OS extended and therefore will not complain about it. You can leave them connected while in XP.
    One thing I would recommend is that when you are in the process of installing Windows XP via Boot Camp then I would recommend that you remove all external peripherals with the exception of the mouse and keyboard. This will eliminate any possible complications during installation. You can attach all of them once installation of XP is completed.
    Axel F.

  • NEW Macbook air and external HDD with windows files

    Hi,
    I just bought (2 days ago) my first MAC (finally). After so many years of working with windows it was time to get of the dark side . Anyway, this is not my first time around apple products (I had iphones and ipads) so I know some basic stuff like iCloud, keychain etc. I bought 13inc macbook air, 128 GB SSD.
    Now this is my problem:
    Although I worked on a windows computer I was saving all my files (work related, movies, music, tvshows, photos- a lot of them) on my external HDD (500 GB). Now, when I transfered to Mac I would like to have my Word, PPT and music files on my mac but not the photos, those I would like to keap on my EHDD. Can this actually work without some work around file extensions and EHDD formating? Can I use my EHDD like this? I know that it is both for Windows and MAC (it was written on the box).

    I depends in what format the external drive is formatted as to how easy this is going to be.
    I bet there is a good chance it is NTFS. If so, some moderately bad news. The Mac OS can read it, but not write to it natively, unless it is a networked drive.
    Sure, you can add third party functionality to the Mac, so it will write to the external drive, but I would avoid it if possible. If your drive is already formatted FAT 32, or ExFAT, then you can perform cross platform reading and writing, without issue.
    Fortunately we live in a time where most external drives are now relatively inexpensive. If you don't want to, or can't reformat that drive, because you have no space to put the files in the interim (I hope they are not just in place, anyway), consider buying a new external drive for sharing purposes.
    Just my 2 cents.

  • How do i setup itunes only on external drive with windows

    well i have windows xp running on bootcamp. i have my main library on my internal drive on my os x partition.
    i want to have music with xp without putting music on my bootcamp partition ( i think my size is 25 or 35 gig). how do i do this on my external drive? do i install itunes on my windows external partition and just copy my music folder there and then import?
    i want to make sure i have a good idea of what to do before i start fooling around. my windows partition is fat 32 while my bootcamp is ntsf

    Move the iTunes music folder to the desired location, and then drag it into the open iTunes window. iTunes itself must be on the startup disk.
    (33998)

  • How to use an external display with Windows 7 and a Macbook Pro (Unibody)

    I just set up my new Macbook Pro 15 inch with the Windows 7 beta, and noticed that I couldn't get the external monitor to be seen using Windows 7 only. I am using my Dell 30 inch monitor and it was only seeing the laptop's main display. The fix was to download the Nvidia video drivers for the 9 series (e.g. the GeForce 9600/9400), after which it was maically able to see the display.
    The driver can be found here. Enjoy.
    http://www.nvidia.com/object/windows7overview.html

    Does Aero work?
    Maybe it will fix some of my problems:
    http://discussions.apple.com/thread.jspa?threadID=2088220&tstart=0

  • Using external drive with windows and osx 10.5

    I have formated an external drive using disk utility as Fat 32. Mac osx sees it fine but windows does not. I used partition magic to format it as fat 32 and windows sees it fine, but osx still sees it by the old name and doesn't see the files I loaded on it. I did it twice from partition magic with the same result. the mac knows the right amount of free space but doesn't see the directory, it sees the old directory from the mac formatting? Why is partition magic not overwriting the mac formatting, and why won't windows see the mac formatting. HHHEEEELLLPP Please

    I solved the problem by formatting the drive in OSX using mac extended which cleared the ms dos partition the mac created, then I used Partition Magic and created a fat 32 volume. Windows and Leopard see it fine now. Why the Fat 32 formatting from Leopard did not work I can not tell you. A bug maybe or maybe my install has a bug.

  • Using an external hdd with windows on boot camp

    Im looking into using boot camp, and was thinking about the option that you get for seeing files that you create in XP within mac OSX, well, wot would happen if i had an external hdd?
    ive got one connected thru firewire, and when i use "Get Info" it tells me the format is Mac OS Extended.
    Now, would that be recognised within XP, and would i be able to move/store files onto it, and then use them within OSX
    If it could, then it would save me having to use a large partition for XP, and the alternative format type.
    If anyone could help me out
    Cheers
    Jon

    Im looking into using boot camp, and was thinking
    about the option that you get for seeing files that
    you create in XP within mac OSX,
    well, wot would
    happen if i had an external hdd?
    You would need to ensure that both the Mac OS and Windows XP OS had read/write privileges.
    ive got one connected thru firewire, and when i use
    "Get Info" it tells me the format is Mac OS
    Extended.
    Now, would that be recognised within XP,
    No, not without third party software.
    and would i
    be able to move/store files onto it, and then use
    them within OSX
    You could is you used MacDrive which will allow you to read Mac formatted disks on a Windows PC.
    iFelix

  • ACS 4.1 External DB with Windows 2008 AD

    I have the following scenario:
    - ACS ver 4.1.1.23 on Windows 2003 Standard with SP2, Domain controller server
    - The main AD database is running on Windows 2008
    Does anybody knows if I still need to upgrade from 4.1.X.Y to 4.2.X.Y to be able to authenticated users against Windows 2008 AD database?
    Or I only need the 4.2 upgrade when the ACS is installed on a Windows 2008 server?
    Thanks in advanced.
    Oscar Perez

    If ACS is on member server you need to upgrade it to 4.2 patch 9 to make acs work with 2008 DC.
    2008 DC support is included from 4.2 patch 4 but I recommend to go for patch 9.
    Regards,
    ~JG
    Do rate helpful posts

  • SB Live 24bit external problems with windows 7 beta driver

    Hi, I have a problem with my soundcard with the windows 7 beta driver. An unwanted sound come out when I'm doing something like chatting with Yahoo Messenger or buffering Youtube. I don't know what makes it like that, can you guys help me out, please
    Thank you

    Maybe you could start by donating something
    I'm giving you something Creative would never do, so I think I deserve it, don't you think
    Doesn't matter if it is $2 or $5.
    All these Vista Support Packs prove my knowledge and are true modifications, not like the current Youp Pax crappy releases from a dumb person who doesn't even know how a INF file works.

  • Yoga 2 Pro - extremely slow when plugged to an external monitor with Windows 10

    Hi! Like most of you, I was eager to take the step early and try Windows 10 (knowing the risk of running into some problems on the way). Everything works very smoothly, and Win10 is really delightful. The only major problem I've faced is that when I plug an external monitor, every action (launching Firefox for example) takes ages and many apps "doesn't respond". I've downloaded and installed all the drivers for Win10 (included the one for the graphic card). Any idea what is happening or what I could try? Best,François

    Hi. I am suffering the exact same thing. But i think i narrowed down the issue:When i am not using an external monitor - everything works nicely.When I am using an external monitor (and laptop set to "Extend" mode) while laptop screen is open - everything works nicely.When i am using an external monitor (and laptop set to "Extend" mode) while laptop screen is closed - everything becomes extremely slow and laggy.  I wish Lenovo support would provide a solution asap.

  • Itunes directory for external hd with windows xp

    I've put my itunes library on an external hd but when I sync my ipod with it not all of my music syncs. In fact very little does. Also, how do I avoid the conversion of mp3 and still have those music files sync?

    Question #1: Have you verified after putting the music on the external hard drive, that the songs that are not syncing to the iPod still play OK in iTunes?
    Question #2: Which MP3 conversion? I am not aware of any sort of automated conversion to MP3 done by iTunes other than importing a CD and you have your import preference set to encode using MP3. So you will have to be more clear as to what exactly you are referring to.
    Patrick

Maybe you are looking for