Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

can not call Win Api function

mavlik
Beginner
1,516 Views

I useDigital Visual Fortran 6.0 (and Compaq Visual Fortran 6.5)
I write a win32 application using win api functions. Some functions calls successfully,
but function LoadImage doesn't want to be called. I have a error:
Error: This name does not have a type, and must have an explicit type.[LOADIMAGE]
Bitmap = LoadImage(0,&
-------------^
It seems to me that this function didn't declare in Fortran's libraries.
Iwrite the prototype of function below:
The LoadImage function loads an icon, cursor, or bitmap.

HANDLE LoadImage(

HINSTANCE hinst, // handle of the instance that contains the image
LPCTSTR lpszName,// name or identifier of image
UINT uType,// type of image
int cxDesired,// desired width
int cyDesired,// desired height
UINT fuLoad// load flags
);

And my part of code that I try to compile
integer(2) Bitmap
LoadImage("img.bmp"C,0,0)
Bitmap = LoadImage(0, &
"img.bmp"C, &
IMAGE_BITMAP, &
0, &
0, &
IOR(LR_DEFAULTSIZE, LR_LOADFROMFILE) &
)
May be it needs to call this function orsomehow stdcall it...

I need help.

0 Kudos
31 Replies
mavlik
Beginner
437 Views
I' ve made a program that works with .bmp files. One of possibilities of the program is
to write the intensity of each pixel in file as a nubmer. And after data handling I have a matrix of
intensity in .txt file.
I've made in delphi useng WinApi. But I want to make it in Fortran.
I've written in Fortran a part of code and try to compile it.

In "A Fortran 90 Tutorial" by Zane Dodsony I found such construction:
type ExtendedInteger
type( UnsignedExtendedInteger ), pointer :: number
end type ExtendedInteger

type( ExtendedInteger ) sum

If I understood correctly this thung can be applied to the arrays.
And I made so...

type Parr
type(T_RGB), pointer :: arr(100)
end type Parr
type(Parr) p

But it's wrong..
type T_RGB
byte b,r,g
end type T_RGB

type(T_RGB), allocatable:: my_array(:)
......
allocate(my_array(100))
brg = my_array(1)%r

And there is no error while linking. Is it right method to do what I described
above (in pascal and c++) ?

Then I try to make so.


INTEGER(1) FUNCTION GETRVALUE(RGB) ! //result type is byte
REAL*8 RGB ! // DWORD
GetRValue = IAND(rgb,#FF)
END FUNCTION GETRVALUE

REAL*8 brg
............
brg = 0.3*GetRValue(my_array(1)%r)

But during the linking I have:
Warning: Arguments' data types are incompatible with intrinsic procedure, assume EXTERNAL.

[IAND]
GetRValue = IAND(rgb,#FF)
---------------^
Error: The intrinsic data types of the arguments must be the same. [IAND]
GetRValue = IAND(rgb,#FF)
--------------------------^
Error: The type of the actual argument differs from the type of the dummy argument.
brg = 0.3*GetRValue(my_array(1)%r)
------------------------------------------^

I think it is because Argument Type in procedure IAND must be integer....
There is no source code for GetRValue and how it was already written by Mr.tim18 and
Mr. Paul Curtis I made it but DVF don't want to link withut errors...
0 Kudos
TimP
Honored Contributor III
437 Views
When you first asked about the masking operations, you were masking out bytes from an integer. The same operations don't make sense on a double precision value. You could treat a double precision value as a 64-bit integer by using TRANSFER, but it doesn't make sense here.
0 Kudos
Steven_L_Intel1
Employee
437 Views
You are getting compile errors, not link.

Why have you declared RGB to be REAL*8? That makes no sense to me. It is usually an integer type, which is why the compiler is complaining.
0 Kudos
mavlik
Beginner
437 Views
I have some questions...
I try to write the intensity of pixels in .txt file.
There are problems with:
1) Pointer to lpBits
2) How to convert float number to string (I try to use function convertFtoCstring)..
Now the problems occured:
Error: The type of the actual argument differs from the type of the dummy argument.
IsWrite = WriteFile(hFile, s, lstrlen(s), dwBytes, lpOverlap)
-----------------------------------^
Error: This passed length character name has been used in an invalid context.
CHARACTER*(*) s
----------------------^


[cpp]  TYPE (T_RGB), ALLOCATABLE :: P(:)
type (T_RGBTRIPLE), pointer :: lpBits
INTEGER*4 hFile REAL*8 brg integer*4 dwBytes INTEGER(2) WRD LOGICAL IsWrite LOGICAL IsClosed type(T_SECURITY_ATTRIBUTES) lpSecAttr type(T_OVERLAPPED) lpOverlap CHARACTER*(*) s INTEGER*4 FloatToStr //!.............. ALLOCATE(P(10000)) //! P = LOC(lpBits) !// Pointer to lpBits hFile = CreateFile("dataW.txt", GENERIC_WRITE, FILE_SHARE_READ, lpSecAttr, & CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL) WRD = IOR(ISHL(10,8),13) //! division of string DO j=0,H-1 DO i=0,W-1 BRG = 0.3*(P(i+w*j)%r)+0.59*(P(i+w* j)%g)+0.11*(P(i+w*j)%b) // !FloatToStr = convertFtoCstring(s,BRG) !Conver number to string
IsWrite = WriteFile(hFile, s, lstrlen(s), dwBytes, lpOverlap)
S = ' ' //! separator of numbers in file
IsWrite = WriteFile(hFile, s, lstrlen(s), dwBytes, lpOverlap)
END DO !I IsWrite = WriteFile(hFile, WRD, SizeOf(WRD), dwBytes, lpOverlap) END DO !J IsClosed = CloseHandle(hFile) DEALLOCATE(P)
[/cpp]
0 Kudos
mavlik
Beginner
437 Views
It's strange that date of my previous post marked as 24 june...but i've posted it today(27 June)
[Added]
I understand: I've edited myprevious message (by pure accident) instead of new answer ....
0 Kudos
Steven_L_Intel1
Employee
437 Views
Not enough information here to explain the error using lstrlen. I assume you have a USE KERNEL32 or similar in this routine.

Can you show the smallest possible routine that gets this error?
0 Kudos
mavlik
Beginner
437 Views
Not enough information here to explain the error using lstrlen. I assume you have a USE KERNEL32 or similar in this routine.

Can you show the smallest possible routine that gets this error?

I made an attachment of my project

0 Kudos
mavlik
Beginner
437 Views
Dear Steve!
Did you inspect my code? It's in attachment above.

0 Kudos
Steven_L_Intel1
Employee
437 Views
It looks as if this code was written for 16-bit Windows. You have INTEGER(2) declarations for things that should be INTEGER(HANDLE). I haven't gone through the whole thing. There are many mismatches.

Find the declarations of the Win32 API routines in the CVF "Include" folder and compare them to what you are passing.
0 Kudos
mavlik
Beginner
437 Views
My code inserted into Standart Fortran Windows Application and it's located between two lines !------------------
And the length of my code is 56 lines (excluding variables)....
I've corrected variable types in code. My question was bounded up with logic errors, not with syntax errors.
Here is correct a bit corrected code...
[cpp]	implicit none

	type T_RGB
     byte b,r,g 
    end type T_RGB

    TYPE (T_RGB), ALLOCATABLE :: P(:)

	integer*4 hInstance
	integer*4 hPrevInstance
	integer*4 lpszCmdLine
	integer*4 nCmdShow
	integer(HANDLE) Bitmap
	integer(HANDLE) bmDIB
	integer(HANDLE) DC 
	integer*4 i, j
    integer*4 GtObj
	integer*4 Gtbit
    integer*4 W, H
	integer(HANDLE) hBDC
	integer(HANDLE) sobj

	include 'opp.fi'

	! Variables
	type (T_WNDCLASS)       wc
	type (T_MSG)            mesg
	type (T_DIBSECTION)	    bmInfo
	type (T_BITMAPINFO) bmiInfo
!	integer(LPVOID) bmiInfo

    type (T_RGBTRIPLE), pointer :: lpBits

!   type (T_RGBTRIPLE) lpBits
!------------------------------------------

  INTEGER*4 hFile   
  REAL*8 brg   
  integer*4 dwBytes   
  INTEGER(2) WRD    !Word;
  LOGICAL IsWrite   
  LOGICAL IsClosed   
  type(T_SECURITY_ATTRIBUTES)  lpSecAttr    
  type(T_OVERLAPPED)           lpOverlap    
!  CHARACTER*(*) s   
  INTEGER*4 FloatToStr    
............
!------------------------------------------------------------------------------------
  DC = GetDC(ghwndMain)
  Bitmap = LoadImage(0,                      &
                     "IMG.BMP"C,             &
					 cIMAGE_BITMAP,          &
                     0,                      &
                     0,                      &
                     IOR(cLR_DEFAULTSIZE, cLR_LOADFROMFILE) &
					)
  GtObj=GetObject(Bitmap,SizeOf(bmInfo),LOC(bmInfo))
  W = bmInfo%dsBm%bmWidth
  H = bmInfo%dsBm%bmHeight

  hBDC = CreateCompatibleDC(dc)
  sobj = SelectObject(hBDC, Bitmap)
  sobj = BitBlt(dc, 0, 0, w, h, hBDC, 0, 0, SRCCOPY)
  bmiInfo%bmiHeader%biWidth=W            ! // Width
  bmiInfo%bmiHeader%biHeight=H           ! // Height
  bmiInfo%bmiHeader%biPlanes=1           ! // always 1
  bmiInfo%bmiHeader%biBitCount=24        ! // 3 byutes per pixel
  bmiInfo%bmiHeader%biCompression=BI_RGB ! // no conpression
  bmiInfo%bmiHeader%biSizeImage=0        ! // size iz unknown
  bmiInfo%bmiHeader%biXPelsPerMeter=2834 ! // pixels per meter,X.
  bmiInfo%bmiHeader%biYPelsPerMeter=2834 ! // pixels per meter,Y.
  bmiInfo%bmiHeader%biClrUsed=0          ! // 
  bmiInfo%bmiHeader%biClrImportant=0     ! // 
  bmiInfo%bmiHeader%biSize=SizeOf(bmiInfo%bmiHeader) !// 
  bmDIB = CreateDIBSection(DC,bmiInfo,DIB_RGB_COLORS,LOC(lpBits),0,0)
 
!  bmiInfo%bmiHeader%biWidth=W            !// 
!  bmiInfo%bmiHeader%biHeight=H           !// 
!  bmiInfo%bmiHeader%biPlanes=1           !// 
!  bmiInfo%bmiHeader%biBitCount=24        !// 
!  bmiInfo%bmiHeader%biCompression=BI_RGB !// 
!  bmiInfo%bmiHeader%biSize=SizeOf(bmiInfo%bmiHeader) !

ALLOCATE(P(1000))   
  P = LOC(lpBits) ! Pointer to lpBits   
hFile = CreateFile("dataW.txt", GENERIC_WRITE, FILE_SHARE_READ, lpSecAttr, &   
                                CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL)   
WRD = IOR(ISHL(10,8),13) ! division of string   

!//Writing matrix of pixel intensity in .txt file  
DO j=0,H-1   
 DO i=0,W-1   
  BRG = 0.3*(P(i+w*j)%r)+0.59*(P(i+w* j)%g)+0.11*(P(i+w*j)%b) !Intensity of Pixel   
  FloatToStr = convertFtoCstring(s,BRG)  !Conver number to string 
  IsWrite = WriteFile(hFile, s, lstrlen(s), dwBytes, lpOverlap)  
  S = ' ' ! separator between numbers in .txt file 
  IsWrite = WriteFile(hFile, s, lstrlen(s), dwBytes, lpOverlap) 
 END DO !I   
 IsWrite = WriteFile(hFile, WRD, SizeOf(WRD), dwBytes, lpOverlap) !goto next line (write a symbol ofline division )  
END DO !J   
  
IsClosed = CloseHandle(hFile)   
  
DEALLOCATE(P) 
!------------------------------------------------------------------------------------
[/cpp]

0 Kudos
Steven_L_Intel1
Employee
437 Views
Someone else perhaps can help you with the logic errors.
0 Kudos
Reply