Using PI API with Visual Basic 6.0

osi.jpg

The PI API provides a common programmer interface to PI System information.

The API is two files: PIAPI32.DLL & PILOG32.DLL which are the foundation of PI networking and data functionality
PIAPI32.dll – contains all of the “C” language functions necessary for any of the PI clients (including PI ProcessBook & PI DataLink) or any of PI’s high speed interfaces to interact with PI: reading and writing data, buffering system, informational functions, etc.
PILOG32.dll – contains all of the “C” language functions necessary to connect to PI servers, logon with security, and create and interpret data packets.

Read the rest of this entry »

ATL对象多线程访问临界锁的实现

1. 几个临界区类

ATL将Windows临界区封装了一下,即CComCriticalSection和CComAutoCriticalSection类。两者的实现如下(精简):

class CComCriticalSection
{
public:
    
CComCriticalSection()
    
{  memset(&m_sec, 0, sizeof(CRITICAL_SECTION));   }
    
HRESULT Lock()
    
{  EnterCriticalSection(&m_sec); return S_OK; }
    
HRESULT Unlock()
    
{ LeaveCriticalSection(&m_sec); return S_OK; }
    
HRESULT Init()
    
{
        
InitializeCriticalSection(&m_sec);
        
return S_OK;
    
}
    
HRESULT Term()
    
{ DeleteCriticalSection(&m_sec); return S_OK; }
 
    
CRITICAL_SECTION m_sec;
};
 
class CComAutoCriticalSection : public CComCriticalSection
{
public:
    
CComAutoCriticalSection()
    
{ HRESULT hr = CComCriticalSection::Init(); }
    ~
CComAutoCriticalSection()
    
{ CComCriticalSection::Term(); }
private:
    
HRESULT Init();
    
HRESULT Term();
};

Read the rest of this entry »

ATL引用计数器的实现

COM对象必须在套间中运行。套间分为单线程套间和多线程套间。在单线程套间中,套间保证COM对象实例仅有一个线程可以访问,而在多线程套间中,COM对象实例可同时被多个线程访问。因此,在多线程套间中执行的COM对象必须解决多线程访问的同步和冲突等线程安全相关问题。

引用计数器管理的实现——CComObjectRootEx

ATL使用CComObjectRootEx类来实现对COM对象计数器的管理,因此,所有的基于ATL的COM对象必须从该类继承。CComObjectRootEx类的声明和实现如下(精简):
Read the rest of this entry »

VC++多线程下内存操作的优化

许多程序员发现用VC++编写的程序在多处理器的电脑上运行会变得很慢,这种情况多是由于多个线程争用同一个资源引起的。对于用VC++编写的程序,问题出在VC++的内存管理的具体实现上。以下通过对这个问题的解释,提供一个简便的解决方法,使得这种程序在多处理器下避免出现运行瓶颈。这种方法在没有VC++程序的源代码时也能用。
Read the rest of this entry »