1. Video Capture
- Posted by jordah ferguson <jorfergie03 at yahoo.com> Oct 04, 2002
- 424 views
Hi All, I was doing some simple coding last night and got disappointing results, those annoying enuff to make you dump a project. i keep getting the message saying my AVI capture driver is poorly installed. i have run this same program on my dads computer and it still gives me the same result. If the it works on any other systems without erroring out please inform me. And if you have any idea how i can properly install a video capture driver please inform me. The first half of the code is my latest low-level routines include file. the real code is at the bottom. Please give me feeback Jordah Ferguson --------------------------------------------------------- --File : SpyLoJiK ver 0.0.1 --Version: 0.0.1 --Date : 1/10/2002 --Author : Jordah Ferguson --------------------------------------------------------- include dll.e include msgbox.e --------------------------------------------------------- -- Start of the latest version of llrtns.e By me :) --------------------------------------------------------- global constant CHAR = #01000001, UCHAR = #02000001, SHORT = #01000002, USHORT = #02000002, INT = #01000004, UINT = #02000004, LONG = INT , ULONG = UINT , POINTER = ULONG , FLOAT = #03000004, DOUBLE = #03000008, BOOL = CHAR , BYTE = CHAR , WORD = SHORT , UWORD = USHORT , DWORD = ULONG , PTR = POINTER , LPSZ = #04000004, FLOAT32 = FLOAT , FLOAT64 = DOUBLE , HANDLE = ULONG -------------------[ Structure Constants ]------------------- constant lladdress = 1, llsize = 2, llctype = 3, llevalue = 4, lloffset = 5 --------------------------------------------------------- constant kernel32 = open_dll("kernel32.dll"), HEAP_ZERO_MEMORY = #00000008, HEAP_NO_SERIALIZE = #00000001, HEAP_GROWABLE = #00000002, zHeapCreate = define_c_func(kernel32, "HeapCreate", {C_LONG, C_LONG, C_LONG}, C_LONG), zHeapAlloc = define_c_func(kernel32, "HeapAlloc", {C_LONG, C_LONG, C_LONG}, C_LONG), zHeapFree = define_c_func(kernel32, "HeapFree", {C_LONG, C_LONG, C_LONG}, C_LONG), zHeapDestroy = define_c_func(kernel32, "HeapDestroy", {C_LONG}, C_LONG), zlstrlen = define_c_func(kernel32, "lstrlenA",{C_POINTER}, C_INT) -------------------------------------------------------- atom InternalHeap --------------------------------------------------------- global type Struct(sequence x) if length(x) != 5 then return 0 else return atom(x[1]) and integer(x[2]) and sequence(x[3]) and sequence(x[4]) and sequence(x[5]) end if end type --------------------------------------------------------- global type string(sequence s) object x for i = 1 to length(s) do x = s[i] if integer(x) then if x < 0 or x > #FF then return 0 end if else return 0 end if end for return 1 end type --------------------------------------------------------- global function HeapCreate(integer size) return c_func(zHeapCreate,{or_bits(HEAP_NO_SERIALIZE,HEAP_GROWABLE),size,0}) end function --------------------------------------------------------- global function HeapDestroy(atom Heap) return c_func(zHeapDestroy,{Heap}) end function --------------------------------------------------------- global function HeapAlloc(atom heap,atom size) return c_func(zHeapAlloc,{heap,or_bits(HEAP_NO_SERIALIZE,HEAP_ZERO_MEMORY),size}) end function --------------------------------------------------------- global function HeapFree(atom heap, atom pointer) return c_func(zHeapFree,{heap,HEAP_NO_SERIALIZE,pointer}) end function --------------------------------------------------------- procedure Init_library() InternalHeap = HeapCreate(16384) if InternalHeap = 0 then puts(1,"Out of memory") end if end procedure -------------------[ Memory Routines ]------------------- global function Alloc(object data) atom MemPointer,len_ if atom(data) then MemPointer = HeapAlloc(InternalHeap,data) if not MemPointer then puts(1,"Out of memory") end if return MemPointer elsif string(data) then len_ = length(data) MemPointer = Alloc(len_+1) poke(MemPointer,data ) poke(MemPointer+len_,0) return MemPointer else -- Allocate objects: Check my lib in RDS Archives return 0 end if end function --------------------------------------------------------- global procedure Free(atom pointer) if pointer then if not HeapFree(InternalHeap,pointer) then return end if end if end procedure --------------------------------------------------------- global procedure FreeAllMem() if not HeapDestroy(InternalHeap) then end if end procedure -------------------[ Accessing the Memory ]------------------- global function lstrlen(atom addr) return c_func(zlstrlen,{addr}) end function --------------------------------------------------------- global function PeekString(atom addr) return peek({addr,lstrlen(addr)}) end function --------------------------------------------------------------------- -- C - STRUCTURE HANDLING ROUTINES --------------------------------------------------------------------- procedure SmartPoke(atom address,atom Cconstant,object value) atom membit if Cconstant = CHAR or Cconstant = UCHAR then poke(address,value) return elsif Cconstant = SHORT or Cconstant = USHORT then poke(address,{and_bits(value,#FF),floor(value/#100)}) return elsif Cconstant = LONG or Cconstant = ULONG then poke4(address,value) return elsif Cconstant = FLOAT then poke(address, machine_func(48,value)) return elsif Cconstant = DOUBLE then poke(address, machine_func(46,value)) return elsif Cconstant = LPSZ then membit = peek4u(address) if membit > 0 then Free(membit) end if poke4(address,Alloc(value)) end if end procedure -------------------------------------------------------* function SmartPeek(atom address,atom Cconstant) atom membit if Cconstant = CHAR then membit = peek(address) return (membit-(#100*(and_bits(membit,#80)!=0))) elsif Cconstant = UCHAR then return peek(address) elsif Cconstant = USHORT then return (peek(address)+(peek(address+1)*#100)) elsif Cconstant = SHORT then membit = (peek(address)+(peek(address+1)*#100)) return (membit - (#10000*(membit>=#8000))) elsif Cconstant = LONG then return peek4s(address) elsif Cconstant = ULONG then return peek4u(address) elsif Cconstant = FLOAT then return machine_func(47,peek({address,4})) elsif Cconstant = DOUBLE then return machine_func(49,peek({address,8})) elsif Cconstant = LPSZ then membit = peek4u(address) if membit > 0 then return PeekString(membit) else return {} end if end if return 0 end function -------------------------------------------------------* global function sizeOf( object data ) if atom(data) then return and_bits(data,#FFFF) else return data[llsize] end if end function --------------------------------------------------------* global function addressOf(object data) atom pointer sequence offsetSeq,evalueSeq,dat integer loc pointer = 0 if Struct(data) then return data[lladdress] else dat = data[1] data= data[2] if Struct(dat) and string(data) then offsetSeq = dat[lloffset ] evalueSeq = dat[llevalue ] pointer = dat[lladdress] loc = find(data,evalueSeq) if loc then return (pointer + offsetSeq[loc]) end if end if end if return 0 end function -------------------------------------------------------* global function AssociatePointer(sequence Structure,atom newMem) atom Addr if newMem = -1 then Addr = Structure[lladdress] if Addr then Free(Addr) end if Structure[lladdress] = Alloc(sizeOf(Structure)) else Structure[lladdress] = newMem end if return Structure end function -------------------------------------------------------* global function AllocateStructure(sequence Structure) return AssociatePointer(Structure,-1) end function -------------------------------------------------------* global function FreeStructure(sequence structure) atom MemAddr MemAddr = structure[lladdress] if MemAddr then Free(structure[lladdress]) structure[lladdress] = 0 end if return structure end function -------------------------------------------------------* global function defineStructure(sequence data) integer xOff atom last object cConstant,Holder sequence ctypeSeq,offsetSeq,evalueSeq ctypeSeq = {} offsetSeq = {} evalueSeq = {} xOff = 0 for i = 1 to length(data) by 1 do cConstant = data[i][1] Holder = data[i][2] if atom(cConstant) then ctypeSeq = append(ctypeSeq,cConstant) evalueSeq = append(evalueSeq,Holder ) offsetSeq = append(offsetSeq,xOff ) xOff += sizeOf(cConstant ) elsif Struct(cConstant) then if i = 1 then ctypeSeq = cConstant[llctype ] evalueSeq = cConstant[llevalue] offsetSeq = cConstant[lloffset] last = length(offsetSeq) xOff = offsetSeq[last]+sizeOf(ctypeSeq[last]) else last = ctypeSeq[length(ctypeSeq)] ctypeSeq &= cConstant[llctype ] evalueSeq&= cConstant[llevalue] xOff = sizeOf(last) offsetSeq&= (xOff+offsetSeq[length(offsetSeq)]+cConstant[lloffset]) last = length(offsetSeq) xOff = offsetSeq[last]+sizeOf(ctypeSeq[last]) end if else last = cConstant[1] ctypeSeq = append(ctypeSeq,last ) evalueSeq = append(evalueSeq,Holder) offsetSeq = append(offsetSeq,xOff ) xOff += sizeOf(last)*cConstant[2] end if end for return {0,xOff,ctypeSeq,evalueSeq,offsetSeq} end function -------------------------------------------------------* global procedure Store(sequence Structure,sequence data) sequence item integer loc,len_ atom ctype_item,offset_item,MemAddr len_ = length(data) if len_ = 0 then mem_set(addressOf(Structure),0,sizeOf(Structure)) return end if if len_ = 2 and string(data[1]) then data = {data} len_ = 1 end if for i = 1 to len_ by 1 do item = data[i][1] MemAddr= Structure[lladdress] loc = find(item,Structure[llevalue]) if loc then ctype_item = Structure[llctype ][loc] offset_item = Structure[lloffset][loc] MemAddr += offset_item SmartPoke(MemAddr,ctype_item,data[i][2]) end if end for end procedure -------------------------------------------------------* global function Fetch(sequence Structure,sequence data) sequence result,evalueSeq,ctypeSeq,offsetSeq,name integer len_,loc atom MemAddr evalueSeq = Structure[llevalue ] ctypeSeq = Structure[llctype ] MemAddr = Structure[lladdress] offsetSeq = Structure[lloffset ] len_ = length(data) if not len_ then loc = length(evalueSeq) result = repeat(0,loc) for i = 1 to loc by 1 do result[i] = SmartPeek(MemAddr+offsetSeq[i],ctypeSeq[i]) end for return result end if if string(data) then loc = find(data,evalueSeq) if loc then return SmartPeek(MemAddr+offsetSeq[loc],ctypeSeq[loc]) else return 0 end if end if result = repeat(0,len_) for i = 1 to len_ by 1 do name = data[i] loc = find(name,evalueSeq) if loc then result[i] = SmartPeek(MemAddr+offsetSeq[loc],ctypeSeq[loc]) end if end for return result end function -------------------[ Handling Bits ]------------------- global function or_all(sequence s) atom ret ret = 0 for i = 1 to length(s) do ret = or_bits(ret,s[i]) end for return ret end function ------------------------------------------------------------- global function LOWORD(atom long) return and_bits(long,#FFFF) end function ------------------------------------------------------------- global function HIWORD(atom long) return floor(long/#10000) end function ------------------------------------------------------------- global function shift_left (atom x, integer count) return x * power (2, count) end function ------------------------------------------------------------- global function shift_right(atom x, integer count) return floor(x / power(2,count)) end function ------------------------------------------------------------- global function MAKELONG (atom a, atom b) return or_bits (a, shift_left (b, 16)) end function ------------------------------------------------------------- global function MAKEWORD( integer lower, integer higher) lower = and_bits(lower, #FF ) higher = and_bits(higher, #FF) return higher*#100 + lower end function ------------------------------------------------------------- global function abs(object x) return x*((x>0)-(x<0)) end function ------------------------------------------------------------- Init_library() --******************************************************* -- Start of Actual Program --******************************************************* -- required DLL's constant user32 = open_dll("user32.dll" ), avicap32 = open_dll("AVICAP32.dll"), -- Required Functions zDefWindowProc = define_c_func(user32, "DefWindowProcA",{PTR,INT,LONG,LONG},PTR), zCreateWindowEx = define_c_func(user32, "CreateWindowExA", {LONG,PTR,INT,LONG,INT,INT,INT,INT,INT,INT,INT,INT},INT), zRegisterClassEx = define_c_func(user32, "RegisterClassExA", {PTR},INT), zLoadCursor = define_c_func(user32, "LoadCursorA",{LONG,PTR},LONG), zMoveWindow = define_c_func(user32, "MoveWindow",{LONG,INT,INT,INT,INT,SHORT},USHORT), zSendMessage = define_c_func(user32, "SendMessageA",{LONG,UINT,LONG,LONG},LONG), zLoadIcon = define_c_func(user32, "LoadIconA",{INT,PTR},LONG), zGetMessage = define_c_func(user32, "GetMessageA", {POINTER,LONG,UINT,UINT},INT), zTranslateMessage = define_c_proc(user32, "TranslateMessage",{POINTER}), zDispatchMessage = define_c_proc(user32, "DispatchMessageA",{POINTER}), zPostQuitMessage = define_c_proc(user32, "PostQuitMessage", {INT}), zcapCreateCaptureWindow = define_c_func(avicap32,"capCreateCaptureWindowA",{PTR,DWORD,INT,INT,INT,INT,LONG,INT},LONG), zcapGetDriverDescription= e_c_func(avicap32,"capGetDriverDescriptionA",{UINT,LONG,LONG,LONG},LONG) , -- Some Constants: WM_CREATE = 1, WM_CLOSE = 16, WM_SIZE = #5, WM_USER = 1024, WM_CAP_START = WM_USER, WM_CAP_DRIVER_CONNECT= WM_CAP_START + 10, WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START + 2, CapWndStyle = or_bits(#10000000,#40000000), ProgName = "AVI Capture Demonstration by Jordah Ferguson 2002", ClassName = "AVI Capture: Lojik Software" atom MainWnd,CaptWnd MainWnd = 0 CaptWnd = 0 -------------------[ WNDCLASSEX STRUCTRURE ]------------ Struct WNDCLASSEX,POINTAPI,MSG WNDCLASSEX = defineStructure({ {UINT ,"cbSize" }, {UINT ,"style" }, {PTR ,"lpfnWndProc" }, {INT ,"cbClsExtra" }, {INT ,"cbWndExtra" }, {HANDLE,"hInstance" }, {HANDLE,"hIcon" }, {HANDLE,"hCursor" }, {HANDLE,"hbrBackground"}, {PTR ,"lpszMenuName" }, {LPSZ ,"lpszClassName"}, {HANDLE,"hIconSm" }}) WNDCLASSEX = AllocateStructure(WNDCLASSEX) -------------------[ POINTAPI Structure ]---------------- POINTAPI = defineStructure({ {LONG,"x"}, {LONG,"y"}}) -------------------[ MSG Structure ]------------------- MSG = defineStructure({ {HANDLE ,"hwnd" }, {UINT ,"message"}, {WORD ,"wParam" }, {LONG ,"lParam" }, {DWORD ,"time" }, {POINTAPI,"" }}) MSG = AllocateStructure(MSG) constant MSGPOINTER = addressOf(MSG) -------------------[ Error Box: MACRO] procedure Error(sequence msg) if message_box(msg,"Spy LoJik 2002",MB_ICONINFORMATION) then end if end procedure --------------------------------------------------------- integer junk,ret -- Wrap of the functions procedure RegisterClassEx(atom lp) ret = c_func(zRegisterClassEx,{lp}) if not ret then Error("Failed to reister class") end if end procedure --------------------------------------------------------- function CreateWindowEx(atom ex,sequence lpsz,sequence wndname,atom st, atom x,atom y,atom cx,atom cy,atom pHwnd) atom buffer1,buffer2 buffer1 = Alloc(lpsz) buffer2 = Alloc(wndname) ret = c_func(zCreateWindowEx,{ex,buffer1,buffer2,st,x,y,cx,cy,pHwnd,0,instance(),0}) if not ret then Error("CreateWindowEx failed") end if Free(buffer1) Free(buffer2) return ret end function --------------------------------------------------------- function SendMessage(atom hwnd,atom msg,atom wParam,atom lParam) return c_func(zSendMessage,{hwnd,msg,wParam,lParam}) end function --------------------------------------------------------- function capCreateCaptureWindow(sequence Name,atom ExS,atom x,atom y,atom cx,atom cy,atom pHwnd,atom cId) atom buffer,ret buffer = Alloc(Name) ret = c_func(zcapCreateCaptureWindow,{buffer,ExS,x,y,cx,cy,pHwnd,cId}) if not ret then Error("Failed to create the capture window") end if Free(buffer) return ret end function --------------------------------------------------------- procedure GetDriverDescription() atom buffer1,buffer2 sequence Desc Desc = {} buffer1 = Alloc(80) buffer2 = Alloc(80) for n = 1 to 10 do junk = c_func(zcapGetDriverDescription,{buffer1,80,buffer2,80}) Desc &= PeekString(buffer1)&" "&PeekString(buffer2) &"\n" end for Error("Device Names: Device Versions\n"&Desc) Free(buffer1) Free(buffer2) end procedure --------------------------------------------------------- ------[ Callack Functions: The real Code at work~ ]------ --------------------------------------------------------- function ErrorCallBack(atom hwnd,atom ErrId,atom lp) if hwnd != CaptWnd then return 0 elsif not ErrId then return 1 else Error(sprintf("Code: %d \nMSG: ",ErrId)&PeekString(lp)) end if return 1 end function constant ECB = call_back(routine_id("ErrorCallBack")) --------------------------------------------------------- atom xPos,yPos function WndProc(atom hwnd,atom msg,atom wParam,atom lParam) if msg = WM_CREATE then CaptWnd = capCreateCaptureWindow(ClassName,CapWndStyle,10,10,180,180,hwnd,1) GetDriverDescription() junk = SendMessage(CaptWnd,WM_CAP_SET_CALLBACK_ERROR,0,ECB) junk = SendMessage(CaptWnd,WM_CAP_DRIVER_CONNECT,0,0) elsif msg = WM_SIZE then xPos = LOWORD(lParam) yPos = HIWORD(lParam) junk = c_func(zMoveWindow,{CaptWnd,0,0,xPos,yPos-50,1}) elsif msg = WM_CLOSE then if hwnd = MainWnd then c_proc(zPostQuitMessage,{0}) end if end if return c_func(zDefWindowProc,{hwnd,msg,wParam,lParam}) end function constant lpfnWndProc = call_back(routine_id("WndProc")) --------------------------------------------------------- procedure WinMain() atom size,aWNDCLASSEX,icon,cursor aWNDCLASSEX = addressOf(WNDCLASSEX) size = sizeOf(WNDCLASSEX) icon = c_func(zLoadIcon,{0,#7F04}) cursor = c_func(zLoadCursor,{0,#7F00}) Store(WNDCLASSEX,{ {"cbSize" ,size }, {"lpfnWndProc" ,lpfnWndProc}, {"hInstance" , instance()}, {"hIcon" , icon }, {"hCursor" , cursor }, {"style" , #0020 }, -- CS_OWNDC {"hbrBackground", 16 }, {"lpszClassName", ClassName }}) RegisterClassEx(aWNDCLASSEX) WNDCLASSEX = FreeStructure(WNDCLASSEX) MainWnd = CreateWindowEx(0,ClassName,ProgName, #104F0000, --or_bits(WS_OVERLAPPEDWINDOW,WS_VISIBLE) #80000000, -- CW_USEDEFAULT #80000000, -- CW_USEDEFAULT 400,400,0) while c_func(zGetMessage,{MSGPOINTER,0,0,0}) do c_proc(zTranslateMessage, {MSGPOINTER}) c_proc(zDispatchMessage, {MSGPOINTER}) end while end procedure --------------------------------------------------------- WinMain() FreeAllMem()
2. Re: Video Capture
- Posted by pampeano at rocketmail.com Oct 04, 2002
- 419 views
Hi Jordah, Your code works great on my computer. It doesn't display any driver installed, but when i click OK it displayes the image ok. I tried to make it to capture the movement, but i only got a still image. I don't know you've troubles in your computer. Try to make your Windows to recognize it as a capture device (like it recognizes the scanners), maybe that's the problem. My configs: P3 550mhz 256mb Running Win98 SE The camera is Creative (I don't remember the model, i'm at work now) --- jordah ferguson <jorfergie03 at yahoo.com> wrote: > I was doing some simple coding last night and got disappointing > results, those annoying enuff to make you dump a project. i keep > getting > the message saying my AVI capture driver is poorly installed. i have > run > this same program on my dads computer and it still gives me the same > result. If the it works on any other systems without erroring out > please > inform me. And if you have any idea how i can properly install a > video > capture driver please inform me. >
3. Re: Video Capture
- Posted by stabmaster_ at hotmail.com Oct 05, 2002
- 421 views
After fixing the typo on line 470 (it said e_c_func instead of define_c_func) i ran the program, only to get an access violation. If it's of any help, here's the function that caused the crash: 77E9486F push ebp 77E94870 mov ebp,esp 77E94872 push ecx 77E94873 push ecx 77E94874 mov edx,dword ptr [ebp+8] 77E94877 mov eax,dword ptr [ebp+18h] 77E9487A and dword ptr [ebp-4],0 77E9487E push ebx 77E9487F push esi 77E94880 push edi 77E94881 mov edi,dword ptr [edx+1Ch] 77E94884 test eax,eax 77E94886 mov dword ptr [ebp-8],edi 77E94889 je 77E8E03B 77E9488F mov ecx,dword ptr [ebp+14h] 77E94892 mov edx,dword ptr [edx+8] 77E94895 add eax,ecx 77E94897 cmp word ptr [edx+2],1 77E9489C mov dword ptr [ebp+18h],eax 77E9489F jne 77ED0633 77E948A5 mov esi,dword ptr [ebp+10h] 77E948A8 mov edx,dword ptr [ebp+0Ch] 77E948AB sub esi,edx 77E948AD sub eax,ecx 77E948AF sar esi,1 77E948B1 cmp eax,esi 77E948B3 mov dword ptr [ebp-4],esi 77E948B6 jl 77EA2798 77E948BC test byte ptr [ebp+1Dh],4 77E948C0 jne 77E99A44 77E948C6 test esi,esi 77E948C8 jle 77E948DB 77E948CA mov esi,dword ptr [ebp-4] 77E948CD movzx eax,word ptr [edx] 77E948D0 inc edx 77E948D1 mov al,byte ptr [eax+edi] 77E948D4 inc edx 77E948D5 mov byte ptr [ecx],al <-- *CRASH!* 77E948D7 inc ecx 77E948D8 dec esi 77E948D9 jne 77E948CD 77E948DB cmp edx,dword ptr [ebp+10h] 77E948DE jb 77EA27A2 77E948E4 mov eax,dword ptr [ebp-4] 77E948E7 pop edi 77E948E8 pop esi 77E948E9 pop ebx 77E948EA leave 77E948EB ret 18h
4. Re: Video Capture
- Posted by Dan Moyer <DANIELMOYER at prodigy.net> Oct 16, 2002
- 452 views
Jordah, Don't know if this relates to what you're trying to do or not, but there are a bunch of people constructing Personal Video Recorders (Tivo emulator) on Linux boxes. Downloadable code, drivers, & links can be found at: http://www.linuxtv.org/ http://www.cadsoft.de/vdr/ and there's an article talking about it in November Popular Science magazine. Might be an interesting Euphoria / Linux project? Dan Moyer ----- Original Message ----- From: "jordah ferguson" <jorfergie03 at yahoo.com> To: "EUforum" <EUforum at topica.com> Sent: Friday, October 04, 2002 3:10 AM Subject: Video Capture > > Hi All, > I was doing some simple coding last night and got disappointing > results, those annoying enuff to make you dump a project. i keep getting > the message saying my AVI capture driver is poorly installed. i have run > this same program on my dads computer and it still gives me the same > result. If the it works on any other systems without erroring out please > inform me. And if you have any idea how i can properly install a video > capture driver please inform me. > > The first half of the code is my latest low-level routines include > file. the real code is at the bottom. Please give me feeback > > Jordah Ferguson > > > --------------------------------------------------------- > --File : SpyLoJiK ver 0.0.1 > --Version: 0.0.1 > --Date : 1/10/2002 > --Author : Jordah Ferguson > --------------------------------------------------------- > > include dll.e > include msgbox.e > > --------------------------------------------------------- > -- Start of the latest version of llrtns.e By me :) > --------------------------------------------------------- > > global constant > CHAR = #01000001, UCHAR = #02000001, > SHORT = #01000002, USHORT = #02000002, > INT = #01000004, UINT = #02000004, > LONG = INT , ULONG = UINT , > POINTER = ULONG , FLOAT = #03000004, > DOUBLE = #03000008, BOOL = CHAR , > BYTE = CHAR , WORD = SHORT , > UWORD = USHORT , DWORD = ULONG , > PTR = POINTER , LPSZ = #04000004, > FLOAT32 = FLOAT , FLOAT64 = DOUBLE , > HANDLE = ULONG > -------------------[ Structure Constants ]------------------- > > constant > lladdress = 1, > llsize = 2, > llctype = 3, > llevalue = 4, > lloffset = 5 > --------------------------------------------------------- > > constant kernel32 = open_dll("kernel32.dll"), > HEAP_ZERO_MEMORY = #00000008, > HEAP_NO_SERIALIZE = #00000001, > HEAP_GROWABLE = #00000002, > > zHeapCreate = define_c_func(kernel32, "HeapCreate", {C_LONG, C_LONG, > C_LONG}, C_LONG), > zHeapAlloc = define_c_func(kernel32, "HeapAlloc", {C_LONG, C_LONG, > C_LONG}, C_LONG), > zHeapFree = define_c_func(kernel32, "HeapFree", {C_LONG, C_LONG, > C_LONG}, C_LONG), > zHeapDestroy = define_c_func(kernel32, "HeapDestroy", {C_LONG}, C_LONG), > zlstrlen = define_c_func(kernel32, "lstrlenA",{C_POINTER}, C_INT) > -------------------------------------------------------- > atom InternalHeap > --------------------------------------------------------- > > global type Struct(sequence x) > if length(x) != 5 then > return 0 > else > return atom(x[1]) > and integer(x[2]) > and sequence(x[3]) > and sequence(x[4]) > and sequence(x[5]) > end if > end type > --------------------------------------------------------- > > global type string(sequence s) > object x > for i = 1 to length(s) do > x = s[i] > if integer(x) then > if x < 0 or x > #FF then > return 0 > end if > else > return 0 > end if > end for > return 1 > end type > --------------------------------------------------------- > > global function HeapCreate(integer size) > return > c_func(zHeapCreate,{or_bits(HEAP_NO_SERIALIZE,HEAP_GROWABLE),size,0}) <snip> LONG,INT},LONG), > > zcapGetDriverDescription= > e_c_func(avicap32,"capGetDriverDescriptionA",{UINT,LONG,LONG,LONG},LONG) > , > > -- Some Constants: > WM_CREATE = 1, > WM_CLOSE = 16, > WM_SIZE = #5, > WM_USER = 1024, > WM_CAP_START = WM_USER, > WM_CAP_DRIVER_CONNECT= WM_CAP_START + 10, > WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START + 2, > CapWndStyle = or_bits(#10000000,#40000000), > ProgName = "AVI Capture Demonstration by Jordah Ferguson 2002", > ClassName = "AVI Capture: Lojik Software" > > atom MainWnd,CaptWnd > MainWnd = 0 > CaptWnd = 0 > -------------------[ WNDCLASSEX STRUCTRURE ]------------ > Struct WNDCLASSEX,POINTAPI,MSG > WNDCLASSEX = defineStructure({ > {UINT ,"cbSize" }, > {UINT ,"style" }, > {PTR ,"lpfnWndProc" }, > {INT ,"cbClsExtra" }, > {INT ,"cbWndExtra" }, > {HANDLE,"hInstance" }, > {HANDLE,"hIcon" }, > {HANDLE,"hCursor" }, > {HANDLE,"hbrBackground"}, > {PTR ,"lpszMenuName" }, > {LPSZ ,"lpszClassName"}, > {HANDLE,"hIconSm" }}) > WNDCLASSEX = AllocateStructure(WNDCLASSEX) > -------------------[ POINTAPI Structure ]---------------- > POINTAPI = defineStructure({ > {LONG,"x"}, > {LONG,"y"}}) > -------------------[ MSG Structure ]------------------- > MSG = defineStructure({ > {HANDLE ,"hwnd" }, > {UINT ,"message"}, > {WORD ,"wParam" }, > {LONG ,"lParam" }, > {DWORD ,"time" }, > {POINTAPI,"" }}) > MSG = AllocateStructure(MSG) > constant MSGPOINTER = addressOf(MSG) > > -------------------[ Error Box: MACRO] > > procedure Error(sequence msg) > if message_box(msg,"Spy LoJik 2002",MB_ICONINFORMATION) then end if > end procedure > > --------------------------------------------------------- > integer junk,ret > -- Wrap of the functions > > procedure RegisterClassEx(atom lp) > ret = c_func(zRegisterClassEx,{lp}) > if not ret then > Error("Failed to reister class") > end if > end procedure > --------------------------------------------------------- > > function CreateWindowEx(atom ex,sequence lpsz,sequence wndname,atom st, > atom x,atom y,atom cx,atom cy,atom pHwnd) > atom buffer1,buffer2 > buffer1 = Alloc(lpsz) > buffer2 = Alloc(wndname) > ret = > c_func(zCreateWindowEx,{ex,buffer1,buffer2,st,x,y,cx,cy,pHwnd,0,instance(),0 }) > > if not ret then > Error("CreateWindowEx failed") > end if > Free(buffer1) > Free(buffer2) > return ret > end function > --------------------------------------------------------- > > function SendMessage(atom hwnd,atom msg,atom wParam,atom lParam) > return c_func(zSendMessage,{hwnd,msg,wParam,lParam}) > end function > --------------------------------------------------------- > > function capCreateCaptureWindow(sequence Name,atom ExS,atom x,atom > y,atom cx,atom cy,atom pHwnd,atom cId) > atom buffer,ret > buffer = Alloc(Name) > ret = c_func(zcapCreateCaptureWindow,{buffer,ExS,x,y,cx,cy,pHwnd,cId}) > if not ret then > Error("Failed to create the capture window") > end if > Free(buffer) > return ret > end function > --------------------------------------------------------- > > procedure GetDriverDescription() > atom buffer1,buffer2 > sequence Desc Desc = {} > buffer1 = Alloc(80) > buffer2 = Alloc(80) > for n = 1 to 10 do > junk = c_func(zcapGetDriverDescription,{buffer1,80,buffer2,80}) > Desc &= PeekString(buffer1)&" "&PeekString(buffer2) &"\n" > end for > Error("Device Names: Device Versions\n"&Desc) > Free(buffer1) > Free(buffer2) > end procedure > > --------------------------------------------------------- > ------[ Callack Functions: The real Code at work~ ]------ > --------------------------------------------------------- > > function ErrorCallBack(atom hwnd,atom ErrId,atom lp) > if hwnd != CaptWnd then > return 0 > elsif not ErrId then > return 1 > else > Error(sprintf("Code: %d \nMSG: ",ErrId)&PeekString(lp)) > end if > return 1 > end function > constant ECB = call_back(routine_id("ErrorCallBack")) > --------------------------------------------------------- > > atom xPos,yPos > function WndProc(atom hwnd,atom msg,atom wParam,atom lParam) > if msg = WM_CREATE then > CaptWnd = > capCreateCaptureWindow(ClassName,CapWndStyle,10,10,180,180,hwnd,1) > GetDriverDescription() > junk = SendMessage(CaptWnd,WM_CAP_SET_CALLBACK_ERROR,0,ECB) > junk = SendMessage(CaptWnd,WM_CAP_DRIVER_CONNECT,0,0) > elsif msg = WM_SIZE then > xPos = LOWORD(lParam) > yPos = HIWORD(lParam) > junk = c_func(zMoveWindow,{CaptWnd,0,0,xPos,yPos-50,1}) > elsif msg = WM_CLOSE then > if hwnd = MainWnd then > c_proc(zPostQuitMessage,{0}) > end if > end if > return c_func(zDefWindowProc,{hwnd,msg,wParam,lParam}) > end function > constant lpfnWndProc = call_back(routine_id("WndProc")) > --------------------------------------------------------- > > procedure WinMain() > atom size,aWNDCLASSEX,icon,cursor > aWNDCLASSEX = addressOf(WNDCLASSEX) > size = sizeOf(WNDCLASSEX) > icon = c_func(zLoadIcon,{0,#7F04}) > cursor = c_func(zLoadCursor,{0,#7F00}) > Store(WNDCLASSEX,{ > {"cbSize" ,size }, > {"lpfnWndProc" ,lpfnWndProc}, > {"hInstance" , instance()}, > {"hIcon" , icon }, > {"hCursor" , cursor }, > {"style" , #0020 }, -- CS_OWNDC > {"hbrBackground", 16 }, > {"lpszClassName", ClassName }}) > RegisterClassEx(aWNDCLASSEX) > WNDCLASSEX = FreeStructure(WNDCLASSEX) > MainWnd = CreateWindowEx(0,ClassName,ProgName, > #104F0000, --or_bits(WS_OVERLAPPEDWINDOW,WS_VISIBLE) <snip> > > >